<?php
namespace app\common\model;
use think\Model;
use fast\Cols;
use fast\Random;
use fast\Date;

class Module extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $pk = 'itemid';

    protected $auto = ['ip'];
    // 模型初始化
    public static function init(){
        self::event('after_insert', function ($row) {
            $datac = array();
            if(isset($row['islat'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '纬度';
                $datac['columnenname'] = 'lng';
                $datac['columntype'] = 'double';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 1;
                $datac['optionform'] = 'map';
                $datac['options'] = 'baidu';
                $datac['default'] = 0;
                $datac['listorder'] = 300;
                $datac['intro'] = '纬度';
                $m = \app\common\model\Column::create($datac);
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '经度';
                $datac['columnenname'] = 'lat';
                $datac['columntype'] = 'double';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 1;
                $datac['optionform'] = 'map';
                $datac['options'] = 'baidu';
                $datac['default'] = 0;
                $datac['listorder'] = 299;
                $datac['intro'] = '经度';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['issort'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '顺序';
                $datac['columnenname'] = 'listorder';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = 'integer(+)';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 288;
                $datac['intro'] = '顺序';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['isip'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = 'IP';
                $datac['columnenname'] = 'ip';
                $datac['columntype'] = 'varcharshort';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = '';
                $datac['listorder'] = 278;
                $datac['intro'] = 'IP';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['isdate'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '创建日期';
                $datac['columnenname'] = 'createtime';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 1;
                $datac['optionform'] = 'datetime';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 268;
                $datac['intro'] = '创建日期';
                $m = \app\common\model\Column::create($datac);

                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '更新日期';
                $datac['columnenname'] = 'updatetime';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 1;
                $datac['optionform'] = 'datetime';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 266;
                $datac['intro'] = '更新日期';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['ishit'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '点击量';
                $datac['columnenname'] = 'hits';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 1;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 264;
                $datac['intro'] = '点击量';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['iscatid'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '类别';
                $datac['columnenname'] = 'catid';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 1;
                $datac['optionform'] = 'select3';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 4;
                $datac['intro'] = '类别';
                $m = \app\common\model\Column::create($datac);
                // $datac['itemid'] = str_replace('-','',Random::uuid());
                // $datac['columnname'] = '类别名称';
                // $datac['columnenname'] = 'categoryname';
                // $datac['columntype'] = 'varcharshort';
                // $datac['columncheck'] = '';
                // $datac['cname'] = $row['enname'];
                // $datac['moduleid'] = $row['itemid'];
                // $datac['isintable'] = 0;
                // $datac['isshowlist'] = 1;
                // $datac['isshowadd'] = 0;
                // $datac['isshowedit'] = 0;
                // $datac['isshowwindow'] = 0;
                // $datac['isshowsearch'] = 0;
                // $datac['isoption'] = 0;
                // $datac['optionform'] = '';
                // $datac['options'] = '';
                // $datac['default'] = '';
                // $datac['listorder'] = 296;
                // $datac['intro'] = '类别名称';
                // $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['iszan'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '点赞量';
                $datac['columnenname'] = 'zans';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 1;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 262;
                $datac['intro'] = '点赞量';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['iscomment'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '评论量';
                $datac['columnenname'] = 'comments';
                $datac['columntype'] = 'int';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 1;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 260;
                $datac['intro'] = '评论量';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['isadmin'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '所属管理员';
                $datac['columnenname'] = 'adminid';
                $datac['columntype'] = 'varcharshort';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = '';
                $datac['listorder'] = 258;
                $datac['intro'] = '所属管理员';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['ismember'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '所属会员';
                $datac['columnenname'] = 'memberid';
                $datac['columntype'] = 'bigint';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 0;
                $datac['isshowedit'] = 0;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = 0;
                $datac['listorder'] = 256;
                $datac['intro'] = '所属会员';
                $m = \app\common\model\Column::create($datac);
            }
            if(isset($row['iscontent'])){
                $datac['itemid'] = str_replace('-','',Random::uuid());
                $datac['columnname'] = '介绍';
                $datac['columnenname'] = 'content';
                $datac['columntype'] = 'text';
                $datac['columncheck'] = '';
                $datac['cname'] = $row['enname'];
                $datac['moduleid'] = $row['itemid'];
                $datac['isshowlist'] = 0;
                $datac['isshowadd'] = 1;
                $datac['isshowedit'] = 1;
                $datac['isshowwindow'] = 0;
                $datac['isshowsearch'] = 0;
                $datac['isoption'] = 0;
                $datac['optionform'] = '';
                $datac['options'] = '';
                $datac['default'] = '';
                $datac['listorder'] = 270;
                $datac['intro'] = '介绍';
                $m = \app\common\model\Column::create($datac);
            }
        });
        self::event('after_update', function($row){
            $datac = array();
            $modelcolumn = model('Column');
            if($row['islat']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'lng');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '纬度';
                    $datac['columnenname'] = 'lng';
                    $datac['columntype'] = 'double';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 1;
                    $datac['optionform'] = 'map';
                    $datac['options'] = 'baidu';
                    $datac['default'] = 0;
                    $datac['listorder'] = 300;
                    $datac['intro'] = '纬度';
                    $m = \app\common\model\Column::create($datac);
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '经度';
                    $datac['columnenname'] = 'lat';
                    $datac['columntype'] = 'double';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 1;
                    $datac['optionform'] = 'map';
                    $datac['options'] = 'baidu';
                    $datac['default'] = 0;
                    $datac['listorder'] = 299;
                    $datac['intro'] = '经度';
                    $m = \app\common\model\Column::create($datac);
                }
            }
            
            if($row['issort']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'listorder');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '顺序';
                    $datac['columnenname'] = 'listorder';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = 'integer(+)';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 288;
                    $datac['intro'] = '顺序';
                    $m = \app\common\model\Column::create($datac);
                }
            }
            
            if($row['isip']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'ip');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = 'IP';
                    $datac['columnenname'] = 'ip';
                    $datac['columntype'] = 'varcharshort';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = '';
                    $datac['listorder'] = 278;
                    $datac['intro'] = 'IP';
                    $m = \app\common\model\Column::create($datac);
                }                
            }
            
            if($row['isdate']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'createtime');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '创建日期';
                    $datac['columnenname'] = 'createtime';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 1;
                    $datac['optionform'] = 'datetime';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 268;
                    $datac['intro'] = '创建日期';
                    $m = \app\common\model\Column::create($datac);
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '更新日期';
                    $datac['columnenname'] = 'updatetime';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 1;
                    $datac['optionform'] = 'datetime';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 266;
                    $datac['intro'] = '更新日期';
                    $m = \app\common\model\Column::create($datac);
                }                
            }
            
            if($row['ishit']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'hits');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '点击量';
                    $datac['columnenname'] = 'hits';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 1;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 264;
                    $datac['intro'] = '点击量';
                    $m = \app\common\model\Column::create($datac);
                }                
            }
            
            if($row['iszan']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'zans');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '点赞量';
                    $datac['columnenname'] = 'zans';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 1;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 262;
                    $datac['intro'] = '点赞量';
                    $m = \app\common\model\Column::create($datac);
                }
            }
            
            if($row['iscomment']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'comments');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '评论量';
                    $datac['columnenname'] = 'comments';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 1;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 260;
                    $datac['intro'] = '评论量';
                    $m = \app\common\model\Column::create($datac);
                }
            }

            if($row['iscatid']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'catid');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '类别';
                    $datac['columnenname'] = 'catid';
                    $datac['columntype'] = 'int';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 1;
                    $datac['optionform'] = 'select3';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 4;
                    $datac['intro'] = '类别';
                    $m = \app\common\model\Column::create($datac);
                }
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'categoryname');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '类别名称';
                    $datac['columnenname'] = 'categoryname';
                    $datac['columntype'] = 'varcharshort';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isintable'] = 0;
                    $datac['isshowlist'] = 1;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = '';
                    $datac['listorder'] = 296;
                    $datac['intro'] = '类别名称';
                    $m = \app\common\model\Column::create($datac);
                }
            }
            if($row['isadmin']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'adminid');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '所属管理员';
                    $datac['columnenname'] = 'adminid';
                    $datac['columntype'] = 'varcharshort';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = '';
                    $datac['listorder'] = 258;
                    $datac['intro'] = '所属管理员';
                    $m = \app\common\model\Column::create($datac);
                }
            }
            if($row['ismember']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'adminid');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '所属会员';
                    $datac['columnenname'] = 'memberid';
                    $datac['columntype'] = 'bigint';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 0;
                    $datac['isshowedit'] = 0;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = 0;
                    $datac['listorder'] = 256;
                    $datac['intro'] = '所属会员';
                    $m = \app\common\model\Column::create($datac);
                }
            }

            if($row['iscontent']){
                $arr = $modelcolumn->getColumnsByModel($row['enname'],$row['itemid'],'content');
                if(count($arr)==0){
                    $datac['itemid'] = str_replace('-','',Random::uuid());
                    $datac['columnname'] = '介绍';
                    $datac['columnenname'] = 'content';
                    $datac['columntype'] = 'text';
                    $datac['columncheck'] = '';
                    $datac['cname'] = $row['enname'];
                    $datac['moduleid'] = $row['itemid'];
                    $datac['isshowlist'] = 0;
                    $datac['isshowadd'] = 1;
                    $datac['isshowedit'] = 1;
                    $datac['isshowwindow'] = 0;
                    $datac['isshowsearch'] = 0;
                    $datac['isoption'] = 0;
                    $datac['optionform'] = '';
                    $datac['options'] = '';
                    $datac['default'] = '';
                    $datac['listorder'] = 270;
                    $datac['intro'] = '介绍';
                    $m = \app\common\model\Column::create($datac);
                }
            }

        });
        self::event('after_delete', function($row){
            
        });
    }
    //新增数据的最佳实践原则：使用create方法新增数据，使用saveAll批量新增数据。
    //$user = User::create(array());

    /*
    $user = new User;
    // save方法第二个参数为更新条件
    $user->save(array(),['id' => 1]);
    */

    /*
    主库写入后从主从库读取 'read_master'   => true 复制 设置开启后，一旦你的模型有写入操作，
    那么该请求后续的同一个模型的读操作都会自动从主库读取。
    */

    //多对一
    // public function category(){
    //     return $this->belongsTo('Category','catid','itemid')->field('itemid,name,nickname,thumb');
    // }
    
    //一对多
    public function columns(){
        return $this->hasMany('Column','moduleid');
    }

    public function getCacheById($itemid = ''){
        $arr = cache('module'.$itemid);
        print_r($arr);exit;
    }

    public function setIpAttr(){
        return request()->ip();
    }
    //生成M层。
    public function makemodelphp($name = '',$itemid = ''){
        if($name){
            $ll = Cols::columnread($name);//当前模型的所有列
            $mm = $this->get($itemid);//当前模型

            $mc = model('Column');
            $lls = array();
            //模型生成
            $stringmodel = '<?php'."\n";
            $stringmodel .= 'namespace app\common\model;'."\n";
            $stringmodel .= 'use think\Model;'."\n";
            $stringmodel .= 'use fast\Cols;'."\n";
            $stringmodel .= 'use fast\Date;'."\n";
            $stringmodel .= 'use think\facade\Cache;'."\n";

            $stringmodel .= 'class '.ucfirst($name).' extends Model'."\n";
            $stringmodel .= '{'."\n";
            $stringmodel .= "\t".'protected $pk = \'itemid\';'."\n";
            if($mm['isdate']){
                $stringmodel .= "\t".'// 开启自动写入时间戳字段'."\n";
                $stringmodel .= "\t".'protected $autoWriteTimestamp = \'int\';'."\n";
                $stringmodel .= "\t".'// 定义时间戳字段名'."\n";
                $stringmodel .= "\t".'protected $createTime = \'createtime\';'."\n";
                $stringmodel .= "\t".'protected $updateTime = \'updatetime\';'."\n";
            }
            if($mm['isevent']){
                $stringmodel .= "\t".'public static function init(){'."\n";
                $stringmodel .= "\t\t".'self::event(\'after_insert\', function($row){'."\n";
                $stringmodel .= "\t\t".'});'."\n";
                $stringmodel .= "\t\t".'self::event(\'after_update\', function($row){'."\n";
                $stringmodel .= "\t\t".'});'."\n";
                $stringmodel .= "\t\t".'self::event(\'after_delete\', function($row){'."\n";
                $stringmodel .= "\t\t".'});'."\n";
                $stringmodel .= "\t".'}'."\n";
            }   
            
            if($mm['isip']){
                $stringmodel .= "\t".'public function setIpAttr(){'."\n";
                    $stringmodel .= "\t\t".'return request()->ip();'."\n";
                $stringmodel .= "\t".'}'."\n";
            }
            
            foreach ($ll as $k => $v) {
                switch ($v['optionform']) {
                    case 'datetime':
                        $stringmodel .= "\t".'public function get'.$k.'Value($value){'."\n";
                        $stringmodel .= "\t\t".'return Date::timetodate($value,3);'."\n";
                        $stringmodel .= "\t".'}'."\n";
                        if($v['columnenname']!='createtime'&&$v['columnenname']!='updatetime'){
                            $stringmodel .= "\t".'public function set'.$k.'($value){'."\n";
                            $stringmodel .= "\t\t".'return strtotime($value);'."\n";
                            $stringmodel .= "\t".'}'."\n";
                        }                        
                        break;
                    case 'radio':
                        if($v['options']){
                            $stringmodel .= "\t".'public function get'.$k.'ValueAttr($value){'."\n";
                            $stringmodel .= "\t\t$".$v['columnenname'].' = [';
                            $arry = json_decode($v['options'],true);
                            foreach ($arry as $kk => $val) {
                                $stringmodel .= $kk.'=>"'.$val.'",';
                            }
                            $stringmodel .= '];'."\n";
                            $stringmodel .= "\t\t".'return $'.$v['columnenname'].'[$value];'."\n";
                            $stringmodel .= "\t".'}'."\n";
                        }
                        break;
                    case 'select':
                        if($v['options']){
                            $stringmodel .= "\t".'public function get'.$k.'ValueAttr($value){'."\n";
                            $stringmodel .= "\t\t$".$v['columnenname'].' = [';

                            $arry = json_decode($v['options'],true);
                            
                            foreach ($arry as $kk => $val) {
                                $stringmodel .= $kk.'=>"'.$val.'",';
                            }
                            $stringmodel .= '];'."\n";
                            $stringmodel .= "\t\t".'return $'.$v['columnenname'].'[$value];'."\n";
                            $stringmodel .= "\t".'}'."\n";
                        }                        
                        break;
                    case 'checkbox':
                        if($v['options']){
                            $stringmodel .= "\t".'public function get'.$k.'ValueAttr($value){'."\n";
                            $stringmodel .= "\t\t$".$v['columnenname'].' = [';
                            $arry = json_decode($v['options'],true);
                            foreach ($arry as $kk => $val) {
                                $stringmodel .= $kk.'=>"'.$val.'",';
                            }
                            $stringmodel .= '];'."\n";
                            $stringmodel .= "\t\t".'$returnstr = \'\';'."\n";
                            $stringmodel .= "\t\t".'$valuearry = explode(\',\', $value);'."\n";
                            $stringmodel .= "\t\t".'for ($i=0; $i < count($valuearry); $i++) {'."\n";
                                $stringmodel .= "\t\t".'$returnstr .= $valuearry[$i].\',\';'."\n";
                            $stringmodel .= "\t\t".'}'."\n";
                            $stringmodel .= "\t\t".'return '.$returnstr.';'."\n";
                            $stringmodel .= "\t".'}'."\n";
                        }                        
                        break;
                    default:
                        # code...
                        break;
                }
                
            }

            if($mm['iscache']){
                $stringmodel .= "\t".'public function get'.ucfirst($name).'ByCache($itemid = 0){'."\n";
                $stringmodel .= "\t\t".'$con = array();$info = array();'."\n";
                $stringmodel .= "\t\t".'$bool = Cache::has(\''.$name.'\'.$itemid);'."\n";
                $stringmodel .= "\t\t".'if($bool){'."\n";
                $stringmodel .= "\t\t\t\t".'//如果缓存存在'."\n";
                $stringmodel .= "\t\t\t\t".'$info = Cache::get(\''.$name.'\'.$itemid);'."\n";    
                $stringmodel .= "\t\t".'}else{'."\n";
                $stringmodel .= "\t\t\t\t".'//如果缓存不存在'."\n";
                $stringmodel .= "\t\t\t\t".'$info = $this->get($itemid);'."\n";
                $stringmodel .= "\t\t\t\t".'$arr = array();'."\n";
                $stringmodel .= "\t\t\t\t".'$arr[\'itemid\'] = $itemid;'."\n";
                foreach ($ll as $k => $v) {
                    if($v['iscache']){
                        $stringmodel .= "\t\t\t\t".'$arr[\''.$v['columnenname'].'\'] = $info?$info[\''.$v['columnenname'].'\']:\'\';'."\n";
                    }
                }
                $stringmodel .= "\t\t\t\t".'Cache::set(\''.$name.'\'.$itemid,$arr);'."\n";
                $stringmodel .= "\t\t\t\t".'$info = Cache::get(\''.$name.'\'.$itemid);'."\n";
                $stringmodel .= "\t\t".'}'."\n";
                $stringmodel .= "\t\t".'return $info;'."\n";
                $stringmodel .= "\t".'}'."\n";
            }
            /*
            public function getCategoryByCache($catid = 0){

            }
            
            //把生成缓存的代码，改一下。
                if($v['iscache']){
                    $stringmodel .= "\t".'public function get'.ucfirst($v['cname']).'ByCache($itemid = 0){'."\n";
                    $stringmodel .= "\t\t".'return cache(\''.$v['cname'].'\'.$itemid);'."\n";
                    $con = array();$name = '';
                    $bool = Cache::has('category'.$catid);
                    if($bool){
                        //如果缓存存在
                        $catinfo = Cache::get('category'.$catid);
                    }else{
                        //如果缓存不存在
                        $catinfo = $this->get($catid);
                        $arr = array();
                        $arr['itemid'] = $catid;
                        $arr['name'] = $catinfo?$catinfo['name']:'';
                        $arr['diyname'] = $catinfo?$catinfo['diyname']:'';
                        Cache::set('category'.$catid,$arr);
                        $catinfo = Cache::get('category'.$catid);
                    }
                    return $catinfo;
                    $stringmodel .= "\t".'}'."\n";
                }
            */

            //一对一
            $llst = $mc->getColumnsByRelate($name,1);
            foreach ($llst as $k => $v) {
                $stringmodel .= "\t".'public function '.$v['rname'].'(){'."\n";
                $stringmodel .= "\t\t".'return $this->hasOne(\''.ucfirst($v['rname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
                $stringmodel .= "\t".'}'."\n";
            }
            //多对一
            $llst = $mc->getColumnsByRelate($name,2);
            foreach ($llst as $k => $v) {
                $stringmodel .= "\t".'public function '.$v['rname'].'(){'."\n";
                $stringmodel .= "\t\t".'return $this->belongsTo(\''.ucfirst($v['rname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
                $stringmodel .= "\t".'}'."\n";
            }
            //一对多
            $llst = $mc->getColumnsByRelate($name,4);
            foreach ($llst as $k => $v) {
                $stringmodel .= "\t".'public function '.$v['cname'].'(){'."\n";
                $stringmodel .= "\t\t".'return $this->hasMany(\''.ucfirst($v['cname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
                $stringmodel .= "\t".'}'."\n";
            }
            $stringmodel .= "\t".'}'."\n";
            $stringmodel .= '?>'."\n";           

            $dir = ADMIN_PATH.DS.'controller'.DS.($mm['dir']?$mm['dir'].DS:'');
            if(!is_dir($dir)){
                mkdir($dir);
            }
            $string = '<?php'."\n";
            $string .= 'namespace app\admin\controller'.($mm['dir']?'\\'.$mm['dir']:'').';'."\n";
            $string .= 'use app\common\controller\Backend;'."\n";
            $string .= 'use think\Controller;'."\n";
            $string .= 'use think\Request;'."\n";
            $string .= 'use think\Session;'."\n";
            $string .= 'use think\\facade\Lang;'."\n";
            $string .= 'use fast\Tree;'."\n";
            $string .= 'use fast\Cols;'."\n";
            $string .= 'use fast\Date;'."\n";
            $string .= 'use fast\Random;'."\n";
            $string .= 'use think\\cache\Driver\File;'."\n";
            $string .= 'class '.ucfirst($name).' extends Backend{'."\n";
            $string .= "\t\t".'protected $model = null;//模型对象'."\n";
            $string .= "\t\t".'protected $columnlist = array();'."\n";
            $string .= "\t\t".'public function initialize(){'."\n";
            $string .= "\t\t\t\t".'parent::initialize();'."\n";
            $string .= "\t\t\t\t".'$this->model = model(\''.ucfirst($name).'\');'."\n";
            $string .= "\t\t\t\t".'$this->columnarry = Lang::load(APP_PATH . $this->request->module() . \'/lang/\' . Lang::detect() . \'/module.php\',\'\',1);'."\n";
            $string .= "\t\t".'}'."\n";
            /*
            $string .= "\t\t".'public function listforajax(){'."\n";
                    $string .= "\t\t\t\t".'$lst = $this->model->order(\'itemid\',\'desc\')->select();'."\n";
                    $string .= "\t\t\t\t".'print_r(json_encode($lst));'."\n";
                    $string .= "\t\t\t\t".'exit;'."\n";
            $string .= "\t\t".'}'."\n";
            */
            $string .= "\t\t".'public function add(){'."\n";
            $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
            $string .= "\t\t\t\t\t\t".'$params = $this->request->post("row/a");'."\n";
            $string .= "\t\t\t\t\t\t".'if ($params){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$fc = new File();'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$this->modelValidate = false;'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'if ($this->dataLimit){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[$this->dataLimitField] = $this->auth->id;'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'try{'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'//是否采用模型验证'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($this->modelValidate){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$name = basename(str_replace(\'\\\'\', \'/\', get_class($this->model)));'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . \'.add\' : true) : $this->modelValidate;'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->model->validate($validate);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
            if($mm['isadmin']){
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\'adminid\'] = $this->auth->itemid;'."\n";
            }
            
            foreach ($ll as $k => $v) {
                if($v['columntype']=='guid'&&$v['columnenname']=='itemid'){
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\''.$v['columnenname'].'\'] = str_replace(\'-\',\'\',Random::uuid());'."\n";
                }
                if($v['optionform']=='datetime'&&$v['isoption']==1&&$v['isshowadd']==1){
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\''.$v['columnenname'].'\'] = strtotime($params[\''.$v['columnenname'].'\']);'."\n";
                }
                if($v['isshowadd']==1&&$v['relate']==3){
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'$'.$v['columnenname'].' = $params[\''.$v['columnenname'].'\'];'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'unset($params[\''.$v['columnenname'].'\']);'."\n";                  
                }
            }        
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$model'.$name.' = \app\common\model\\'.ucfirst($name).'::create($params);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($model'.$name.' !== false){'."\n";
            foreach ($ll as $k => $v) {
                if($v['isshowadd']==1&&$v['relate']==3){
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$'.$v['columnenname'].'array = explode(\',\',$'.$v['columnenname'].');'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'foreach ($'.$v['columnenname'].'array as $k => $v) {'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$b = model(\''.ucfirst($v['cname']).ucfirst($v['rname']).'\')->exists($model'.$name.'->itemid,$v);'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(!$b){'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$paras = array();'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$paras[\''.$v['cname'].'id\'] = $model'.$name.'->itemid;'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$paras[\''.$v['rname'].'id\'] = $v;'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'\app\common\model\\'.ucfirst($v['cname']).ucfirst($v['rname']).'::create($paras);'."\n";
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";                                          
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                }
            }            

            if($mm['iscache']){
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$datacache = array();'."\n";
                foreach ($ll as $k => $v) {
                    if($v['iscache']){
                        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$datacache[\''.$v['columnenname'].'\'] = $model'.$name.'->'.$v['columnenname'].';'."\n";
                    }
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'cache(\''.$name.'\'.$model'.$name.'->itemid,$datacache);'."\n";
            }
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->success();'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->error($this->model->getError());'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";''."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'catch (\think\exception\PDOException $e){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$this->error($e->getMessage());'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'\'));'."\n";
            $string .= "\t\t\t\t".'}else{'."\n";
            foreach ($ll as $k => $v) {
                if($mm['pid']){
                    $mpm = $this->get(['itemid'=>$mm['pid']]);
                    if($v['rname'] == $mpm['enname']){
                      $string .= "\t\t\t\t\t\t\t\t".'$'.$v['columnenname'].' = dsafe($this->request->get(\''.$v['columnenname'].'\'));'."\n";
                      $string .= "\t\t\t\t\t\t\t\t".'$this->view->assign("'.$v['columnenname'].'",$'.$v['columnenname'].');'."\n";
                    }
                }
            }
            $string .= "\t\t\t\t\t\t".'$fc = new File();'."\n";
            $string .= "\t\t\t\t\t\t".'return $this->view->fetch();'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t".'}'."\n";

            $string .= "\t\t"."public function edit(\$ids = NULL){".''."\n";
            //找多对一的关系
            $columnlistmore = model('Column')->getColumnsByRelate($name,2)->toArray();
            if(count($columnlistmore)==0){
                $columnlistmore = array();
            }
            $columnlistone = model('Column')->getColumnsByRelate($name,1)->toArray();
            if(count($columnlistone)==0){
                $columnlistone = array();
            }
            $columnlist = array_merge($columnlistmore, $columnlistone);
            $st1 = '';$st = '';
            if(count($columnlist)>0){
                if(count($columnlist)==0){
                    $st = '->with([';
                    foreach ($columnlist as $k => $v) {
                        $rmodel = $this->get(['enname'=>$v['rname']]);//关联模型
                        if(!$rmodel['iscache']){
                            if($v['relatecolumn']){
                                $st1 .= '\''.$v['rname'].'\'=>function($query){'."\n";
                                $st1 .= "\t\t\t\t\t\t\t\t".'$query->field(\'itemid,'.$v['relatecolumn'].'\');'."\n";
                                $st1 .= "\t\t\t\t\t\t".'}],';
                            }
                        }                
                    }
                    $st1 = substr($st1,0,strlen($st1)-1);
                
                    $st .= $st1.'])';
                }else{
                    $st .= $st1.'';
                }
            }
            $string .= "\t\t\t\t".'$row = $this->model'.$st.'->find($ids);'."\n";
            if(count($columnlist)>0){
                foreach ($columnlist as $k => $v) {
                    $string .= "\t\t\t\t".'$row[\''.$v['rname'].'\'] = model(\''.ucfirst($v['rname']).'\')->get'.ucfirst($v['rname']).'ByCache($row[\''.$v['rname'].'id\']);'."\n";
                    $string .= "\t\t\t\t".'$'.$v['rname'].'str = \'\';'."\n";
                    $string .= "\t\t\t\t".'foreach ($row[\''.$v['rname'].'\'] as $k => $v) {'."\n";
                    $string .= "\t\t\t\t\t\t".'$'.$v['rname'].'str .= $v;'."\n";
                    $string .= "\t\t\t\t\t\t".'$'.$v['rname'].'str .= ",";'."\n";
                    $string .= "\t\t\t\t".'}'."\n";
                    $string .= "\t\t\t\t".'$this->view->assign(\''.$v['rname'].'str\',$'.$v['rname'].'str);'."\n";
                }
            }                
            
            $string .= "\t\t\t\t".'if(isset($row[\'catid\'])){'."\n";
            $string .= "\t\t\t\t\t\t".'$row[\'category\'] = model(\'Category\')->getCategoryByCache($row[\'catid\']);'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            
            $string .= "\t\t\t\t".'$fc = new File();'."\n";
            $string .= "\t\t\t\t".'if (!$row){$this->error(__(\'No Results were found\'));}'."\n";
            $string .= "\t\t\t\t".'$adminIds = $this->getDataLimitAdminIds();'."\n";
            $string .= "\t\t\t\t".'if (is_array($adminIds)){'."\n";
            $string .= "\t\t\t\t\t\t".'if (!in_array($row[$this->dataLimitField], $adminIds)){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$this->error(__(\'You have no permission\'));'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
            $string .= "\t\t\t\t\t\t".'$params = $this->request->post("row/a");'."\n";
            $string .= "\t\t\t\t\t\t".'if ($params){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'try{'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'//是否采用模型验证'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($this->modelValidate){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$name = basename(str_replace(\'\\\'\', \'/\', get_class($this->model)));'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . \'.edit\' : true) : $this->modelValidate;'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$row->validate($validate);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
            foreach ($ll as $k => $v) {
                if($v['optionform']=='datetime'&&$v['isoption']==1&&$v['isshowedit']==1){
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\''.$v['columnenname'].'\'] = strtotime($params[\''.$v['columnenname'].'\']);'."\n";
                }
            }
            if($mm['isadmin']){
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\'adminid\'] = $this->auth->itemid;'."\n";
            } 
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$result = $row->allowField(true)->save($params,[\'itemid\' => $ids]);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($result !== false){'."\n";

            if($mm['iscache']){
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$datacache = array();'."\n";
                foreach ($ll as $k => $v) {
                    if($v['iscache']){
                        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$datacache[\''.$v['columnenname'].'\'] = $params[\''.$v['columnenname'].'\'];'."\n";
                    }
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'cache(\''.$name.'\'.$ids,$datacache);'."\n";
            }
            $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->success();'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'else{$this->error($row->getError());}'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'catch (\think\exception\PDOException $e){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$this->error($e->getMessage());'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'\'));'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("row", $row);'."\n";
            $string .= "\t\t\t\t".'return $this->view->fetch();'."\n";
            $string .= "\t\t".'}'."\n";

            foreach ($columnlistone as $k => $v) {
                $string .= "\t\t".'public function editby'.$v['rname'].'($'.$v['rname'].'id = NULL){'."\n";
                $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
                $string .= "\t\t\t\t\t\t".'$params = $this->request->post("row/a");'."\n";
                $string .= "\t\t\t\t\t\t".'$row = $this->model->get([\''.$v['rname'].'id\'=>$params[\''.$v['rname'].'id\']]);'."\n";
                $string .= "\t\t\t\t\t\t".'if ($params){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'try{'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'//是否采用模型验证'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($this->modelValidate){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$name = basename(str_replace(\'\\\'\', \'/\', get_class($this->model)));'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . \'.edit\' : true) : $this->modelValidate;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$row->validate($validate);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                if($mm['isadmin']){
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\'adminid\'] = $this->auth->itemid;'."\n";
                } 
                $string .= "\t\t\t\t\t\t\t\t\t\t".'if($row){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$result = $row->allowField(true)->save($params,[\''.$v['rname'].'id\' => $params[\''.$v['rname'].'id\']]);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$result = \app\common\model\\'.ucfirst($name).'::create($params);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($result !== false){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->success();'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->error($row->getError());'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'}catch (\\think\\exception\\PDOException $e){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$this->error($e->getMessage());'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'\'));'."\n";
                $string .= "\t\t\t\t".'}else{'."\n";
                $string .= "\t\t\t\t\t\t".'$row = $this->model->get([\''.$v['rname'].'id\'=>$'.$v['rname'].'id]);'."\n";
                $string .= "\t\t\t\t\t\t".'if(isset($row[\'catid\'])){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'$row[\'category\'] = model(\'Category\')->getCategoryByCache($row[\'catid\']);'."\n";
                $string .= "\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t".'$this->view->assign("'.$v['rname'].'id",$'.$v['rname'].'id);'."\n";
                $string .= "\t\t\t\t\t\t".'$this->view->assign("row", $row);'."\n";
                $string .= "\t\t\t\t\t\t".'return $this->view->fetch();'."\n";
                $string .= "\t\t\t\t".'}'."\n";
                $string .= "\t\t".'}'."\n";
            }
            

            $string .= "\t\t".'public function index(){'."\n";
            $string .= "\t\t\t\t".'$columnlist = Cols::columnread(\''.$name.'\');'."\n";
            $string .= "\t\t\t\t".'$searchfileds = array();$searchdefault = array();'."\n";
            $string .= "\t\t\t\t".'$flag = array();$options = array();'."\n";
            $string .= "\t\t\t\t".'foreach($columnlist as $v){'."\n";
            $string .= "\t\t\t\t\t\t".'$flag[] = $v[\'listorder\'];'."\n";
            $string .= "\t\t\t\t\t\t".'if($v[\'options\']){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'//把带有选项的列，提取出来。'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$options[$v[\'columnenname\']] = $v[\'options\'];'."\n";
            
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'if($v[\'isshowsearch\']){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$searchfileds[$v[\'columnenname\']] = $v[\'columntype\'];'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'array_multisort($flag, SORT_ASC, $columnlist);'."\n";
            $string .= "\t\t\t\t".'//设置过滤方法'."\n";
            $string .= "\t\t\t\t".'$this->request->filter([\'strip_tags\']);'."\n";
            $string .= "\t\t\t\t".'//如果发送的来源是Selectpage，则转发到Selectpage'."\n";
            $string .= "\t\t\t\t".'if ($this->request->request(\'pkey_name\')){'."\n";
            $string .= "\t\t\t\t\t\t".'return $this->selectpage();'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            
            foreach ($ll as $k => $v) {
                if($mm['pid']){
                    if($v['rname']!=''){
                        //$string .= "\t\t\t\t".'$searchfileds[\''.$v['columnenname'].'\'] = \''.$v['columntype'].'\';'."\n";
                        $string .= "\t\t\t\t".'$searchdefault[\''.$v['columnenname'].'\'] = \'0\';'."\n";
                    }
                }
            }
            if($mm['pid']){
                $string .= "\t\t\t\t".'list($where, $sort, $order, $offset, $limit) = $this->buildparams($searchfileds,null,$searchdefault);'."\n";
            }else{
                $string .= "\t\t\t\t".'list($where, $sort, $order, $offset, $limit) = $this->buildparams($searchfileds);'."\n";
            }
            $string .= "\t\t\t\t".'$order = \'desc\';'."\n";
            $string .= "\t\t\t\t".'$sort = \'itemid\';'."\n";
            $string .= "\t\t\t\t".'$total = $this->model'."\n";
            $string .= "\t\t\t\t".'->where($where)'."\n";
            $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
            $string .= "\t\t\t\t".'->count();'."\n";
            $string .= "\t\t\t\t".'$totalpage = 1;$page = 1;'."\n";
            $string .= "\t\t\t\t".'if($limit>0){'."\n";
            $string .= "\t\t\t\t\t\t".'$totalpage = $total%$limit==0?intval($total/$limit):intval($total/$limit)+1;'."\n";
            $string .= "\t\t\t\t\t\t".'//总页数'."\n";
            $string .= "\t\t\t\t\t\t".'if($offset>0){$page = intval($offset/$limit)+1;}'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$list = $this->model'."\n";
            $st1 = '';$st = '';
            if(count($columnlist)>0){
                $st = '->with([';
                foreach ($columnlist as $k => $v) {
                    $rmodel = $this->get(['enname'=>$v['rname']]);//关联模型
                    if(!$rmodel['iscache']){
                        if($v['relatecolumn']){
                            $st1 .= '\''.$v['rname'].'\'=>function($query){'."\n";
                            $st1 .= "\t\t\t\t\t\t\t\t".'$query->field(\'itemid,'.$v['relatecolumn'].'\');'."\n";
                            $st1 .= "\t\t\t\t\t\t".'}],';
                        }
                    }                
                }
                $st1 = substr($st1,0,strlen($st1)-1);
                if(count($columnlist)==0){
                    $st .= $st1.'])';
                }else{
                    $st .= $st1.')';
                }
                
            }            
            if($st1){
                $string .= "\t\t\t\t".$st."\n";
            }
            $string .= "\t\t\t\t".'->where($where)'."\n";
            $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
            $string .= "\t\t\t\t".'->limit($offset, $limit)'."\n";
            $string .= "\t\t\t\t".'->select();'."\n";
            $string .= "\t\t\t\t".'for ($i = 0; $i < count($list); $i++) {'."\n";

            $string .= "\t\t\t\t\t\t".'if(isset($list[$i][\'catid\'])){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$catarry = model(\'Category\')->getCategoryByCache($list[$i][\'catid\']);'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\'categoryname\'] = $catarry[\'name\'];'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\'categorydiyname\'] = $catarry[\'diyname\'];'."\n";            
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'unset($list[$i][\'intro\']);unset($list[$i][\'content\']);'."\n";
            
            $string .= "\t\t\t\t\t\t".'foreach ($options as $k => $v) {'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'if(isset($list[$i][$k])){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$arj = json_decode($v,true);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$sarj = isset($arj[$list[$i][$k]])?$arj[$list[$i][$k]]:"";'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$list[$i][$k] = $sarj;'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $st2 = '';
            
            foreach ($columnlist as $k => $v) {
                $rmodel = $this->get(['enname'=>$v['rname']]);//关联模型
                $relatecolumnarry = explode(',',$v['relatecolumn']);

                if($rmodel['iscache']){
                    $relatecolumn = '';
                    for ($ii=count($relatecolumnarry)-1;$ii>=0;$ii--) { 
                        $st2 .= "\t\t\t\t\t\t".'if(cache(\''.$v['rname'].'\'.$list[$i][\'itemid\'])!==null){'."\n";
                        $st2 .= "\t\t\t\t\t\t\t\t".'$datacache = cache(\''.$v['rname'].'\'.$list[$i][\''.$v['columnenname'].'\']);'."\n";
                        $st2 .= "\t\t\t\t\t\t\t\t".'$list[$i][\''.$v['rname'].$relatecolumnarry[$ii].'\'] = $datacache[\''.$relatecolumnarry[$ii].'\'];'."\n";
                        $st2 .= "\t\t\t\t\t\t".'}'."\n";
                    }
                }else{
                    for ($ii=count($relatecolumnarry)-1;$ii>=0;$ii--) {
                        $st2 .= "\t\t\t\t\t\t".'$list[$i][\''.$v['rname'].$relatecolumnarry[$ii].'\'] = $list[$i][\''.$v['rname'].'\'][\''.$relatecolumnarry[$ii].'\'];'."\n";
                    }
                }
            }
            $string .= "\t\t\t\t\t\t".$st2."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$result = array("total" => $total, "rows" => $list);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("lists",$result[\'rows\']);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("listsjson",json_encode($result[\'rows\']));'."\n";
                    
            $string .= "\t\t\t\t".'$this->view->assign("columnlistjson",json_encode($columnlist));'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("columnlist",$columnlist);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("total",$result[\'total\']);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("offset",$offset);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("limit",$limit);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("totalpage",$totalpage);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("page",$page);'."\n";
            $string .= "\t\t\t\t".'return $this->view->fetch(\'index\');'."\n";
            $string .= "\t\t".'}'."\n";

            $string .= "\t\t".'public function select(){'."\n";
            $string .= "\t\t\t\t".'$columnlist = Cols::columnread(\''.$name.'\');'."\n";
            $string .= "\t\t\t\t".'$flag = array();$options = array();'."\n";
            $string .= "\t\t\t\t\t\t".'foreach($columnlist as $v){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$flag[] = $v[\'listorder\'];'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'if($v[\'options\']){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'//把带有选项的列，提取出来。'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$options[$v[\'columnenname\']] = $v[\'options\'];'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'array_multisort($flag, SORT_ASC, $columnlist);'."\n";
            $string .= "\t\t\t\t".'//设置过滤方法'."\n";
            $string .= "\t\t\t\t".'$this->request->filter([\'strip_tags\']);'."\n";
            $string .= "\t\t\t\t".'//如果发送的来源是Selectpage，则转发到Selectpage'."\n";
            $string .= "\t\t\t\t".'if ($this->request->request(\'pkey_name\')){'."\n";
            $string .= "\t\t\t\t\t\t".'return $this->selectpage();'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$searchfileds = array();$searchdefault = array();'."\n";
            foreach ($ll as $k => $v) {
                if($v['isshowsearch']==1){
                    $string .= "\t\t\t\t".'$searchfileds[\''.$v['columnenname'].'\'] = \''.$v['columntype'].'\';'."\n";
                }
                if($mm['pid']){
                    if($v['rname']!=''){
                        $string .= "\t\t\t\t".'$searchfileds[\''.$v['columnenname'].'\'] = \''.$v['columntype'].'\';'."\n";
                        //$string .= "\t\t\t\t".'$searchdefault[\''.$v['columnenname'].'\'] = \'0\';'."\n";
                    }
                }
            }
            if($mm['pid']){
                $string .= "\t\t\t\t".'list($where, $sort, $order, $offset, $limit) = $this->buildparams($searchfileds,null,$searchdefault);'."\n";
            }else{
                $string .= "\t\t\t\t".'list($where, $sort, $order, $offset, $limit) = $this->buildparams($searchfileds);'."\n";
            }
            $string .= "\t\t\t\t".'$order = \'desc\';'."\n";
            $string .= "\t\t\t\t".'$sort = \'itemid\';'."\n";
            $string .= "\t\t\t\t".'$total = $this->model'."\n";
            $string .= "\t\t\t\t".'->where($where)'."\n";
            $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
            $string .= "\t\t\t\t".'->count();'."\n";
            $string .= "\t\t\t\t".'$totalpage = 1;$page = 1;'."\n";
            $string .= "\t\t\t\t".'if($limit>0){'."\n";
            $string .= "\t\t\t\t\t\t".'$totalpage = $total%$limit==0?intval($total/$limit):intval($total/$limit)+1;'."\n";
            $string .= "\t\t\t\t\t\t".'//总页数'."\n";
            $string .= "\t\t\t\t\t\t".'if($offset>0){$page = intval($offset/$limit)+1;}'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$list = $this->model'."\n";
            $st1 = '';$st = '';
            if(count($columnlist)>0){
                $st = '->with([';
                foreach ($columnlist as $k => $v) {
                    $rmodel = $this->get(['enname'=>$v['rname']]);//关联模型
                    if(!$rmodel['iscache']){
                        if($v['relatecolumn']){
                            $st1 .= '\''.$v['rname'].'\'=>function($query){'."\n";
                            $st1 .= "\t\t\t\t\t\t\t\t".'$query->field(\'itemid,'.$v['relatecolumn'].'\');'."\n";
                            $st1 .= "\t\t\t\t\t\t".'}],';
                        }
                    }                
                }
                $st1 = substr($st1,0,strlen($st1)-1);
                if(count($columnlist)==0){
                    $st .= $st1.'])';
                }else{
                    $st .= $st1.')';
                }
                
            }            
            if($st1){
                $string .= "\t\t\t\t".$st."\n";
            }
            $string .= "\t\t\t\t".'->where($where)'."\n";
            $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
            $string .= "\t\t\t\t".'->limit($offset, $limit)'."\n";
            $string .= "\t\t\t\t".'->select();'."\n";
            $string .= "\t\t\t\t".'for ($i = 0; $i < count($list); $i++) {'."\n";

            $string .= "\t\t\t\t\t\t".'if(isset($list[$i][\'catid\'])){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$catarry = model(\'Category\')->getCategoryByCache($list[$i][\'catid\']);'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\'categoryname\'] = $catarry[\'name\'];'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\'categorydiyname\'] = $catarry[\'diyname\'];'."\n";            
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'unset($list[$i][\'intro\']);unset($list[$i][\'content\']);'."\n";
            
            $string .= "\t\t\t\t\t\t".'foreach ($options as $k => $v) {'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'if(isset($list[$i][$k])){'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$arj = json_decode($v,true);'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$sarj = isset($arj[$list[$i][$k]])?$arj[$list[$i][$k]]:"";'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'$list[$i][$k] = $sarj;'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            /**/
            $st2 = '';
            foreach ($columnlist as $k => $v) {
                $rmodel = $this->get(['enname'=>$v['rname']]);//关联模型
                $relatecolumnarry = explode(',',$v['relatecolumn']);
                if($rmodel['iscache']){
                    $relatecolumn = '';
                    for ($ii=count($relatecolumnarry)-1;$ii>=0;$ii--) { 
                        $st2 .= "\t\t\t\t\t\t".'if(cache(\''.$v['rname'].'\'.$list[$i][\'itemid\'])!==null){'."\n";
                        $st2 .= "\t\t\t\t\t\t\t\t".'$datacache = cache(\''.$v['rname'].'\'.$list[$i][\''.$v['columnenname'].'\']);'."\n";
                        $st2 .= "\t\t\t\t\t\t\t\t".'$list[$i][\''.$v['rname'].$relatecolumnarry[$ii].'\'] = $datacache[\''.$relatecolumnarry[$ii].'\'];'."\n";
                        $st2 .= "\t\t\t\t\t\t".'}'."\n";
                    }
                }else{
                    for ($ii=count($relatecolumnarry)-1;$ii>=0;$ii--) {
                        $st2 .= '$list[$i][\''.$v['rname'].''.$relatecolumnarry[$ii].'\'] = $list[$i][\''.$v['rname'].'\'][\''.$relatecolumnarry[$ii].'\'];'."\n";
                    }
                }
            }
            $string .= "\t\t\t\t\t\t".$st2."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$result = array("total" => $total, "rows" => $list);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("lists",$result[\'rows\']);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("listsjson",json_encode($result[\'rows\']));'."\n";
                    
            $string .= "\t\t\t\t".'$this->view->assign("columnlistjson",json_encode($columnlist));'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("columnlist",$columnlist);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("total",$result[\'total\']);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("offset",$offset);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("limit",$limit);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("totalpage",$totalpage);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("page",$page);'."\n";
            $string .= "\t\t\t\t".'$this->view->assign("multiple",$this->request->get(\'multiple\'));'."\n";
            $string .= "\t\t\t\t".'return $this->view->fetch();'."\n";
            $string .= "\t\t".'}'."\n";


            if($mm['isevent']){
                $string .= "\t\t".'/**'."\n";
                $string .= "\t\t".'* 删除'."\n";
                $string .= "\t\t".'*/'."\n";
                $string .= "\t\t".'public function del($ids = ""){'."\n";
                $string .= "\t\t\t\t".'if($ids){'."\n";
                $string .= "\t\t\t\t\t\t".'$model = $this->model->get($ids);'."\n";
                $string .= "\t\t\t\t\t\t".'$model->delete();'."\n";
                $string .= "\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'ids\'));'."\n";
                $string .= "\t\t".'}'."\n";
                $string .= "\t\t".'/**'."\n";
                $string .= "\t\t".'* 删除类别'."\n";
                $string .= "\t\t".'* @internal'."\n";
                $string .= "\t\t".'*/'."\n";
                $string .= "\t\t".'public function dels(){'."\n";
                $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
                $string .= "\t\t\t\t\t\t".'$ids = $this->request->post("ids");'."\n";
                $string .= "\t\t\t\t\t\t".'$idarry = explode(\',\', $ids);'."\n";
                $string .= "\t\t\t\t\t\t".'foreach ($idarry as $k => $v) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'if($v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$model = $this->model->get($v);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$model->delete();'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t".'$this->success();'."\n";
                $string .= "\t\t\t\t\t\t".'exit;'."\n";
                $string .= "\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'ids\'));'."\n";
                $string .= "\t\t".'}'."\n";
            }

            $string .= "\t\t".'public function showlist(){'."\n";
            $string .= "\t\t\t\t".'$ids = $this->request->post(\'ids\');'."\n";
            $string .= "\t\t\t\t".'$ischeck = $this->request->post(\'ischeck\');'."\n";
            $string .= "\t\t\t\t".'model(\'Column\')->where(\'itemid\',$ids)->update([\'isshowlist\'=>($ischeck===\'true\'?1:0)]);'."\n";
            $string .= "\t\t\t\t".'$ll = model(\'Column\')->getColumnsByModel(\''.$name.'\');'."\n";
            $string .= "\t\t\t\t".'$lls = array();'."\n";
            $string .= "\t\t\t\t".'foreach ($ll as $k => $v) {'."\n";
            $string .= "\t\t\t\t\t\t".'$lls[ucfirst($v[\'columnenname\'])] = $v;'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'$string = "<?php return ".var_export($lls, true)."; ?>";'."\n";
            $string .= "\t\t\t\t".'$filename = COLUMN_PATH.DS.\''.$name.'.php\';'."\n";
            $string .= "\t\t\t\t".'$result = file_put_contents($filename, $string);'."\n";
            $string .= "\t\t\t\t".'if(@$fp = fopen($filename,\'wb\')) {'."\n";
            $string .= "\t\t\t\t\t\t".'flock($fp, LOCK_EX);'."\n";
            $string .= "\t\t\t\t\t\t".'$len = fwrite($fp, $string);'."\n";
            $string .= "\t\t\t\t\t\t".'flock($fp, LOCK_UN);'."\n";
            $string .= "\t\t\t\t\t\t".'fclose($fp);'."\n";
            $string .= "\t\t\t\t\t\t".'echo $len;exit;'."\n";
            $string .= "\t\t\t\t".'} else {'."\n";
            $string .= "\t\t\t\t\t\t".'echo \'失败了\';exit;'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t".'}'."\n";

            $string .= "\t\t".'/**'."\n";
            $string .= "\t\t".'* 数据列表返回json数据'."\n";
            $string .= "\t\t".'*/'."\n";
            $string .= "\t\t".'public function ajaxlist(){'."\n";
            $string .= "\t\t\t\t".'$ll = array();$llary = array();$arrwhere = array();$returnarry = array();'."\n";   
            $llst = $mc->getColumnsByRelate($mm['enname'],2);
            foreach ($llst as $k => $v) {
                $string .= "\t\t\t\t".'if($this->request->post(\''.$v['columnenname'].'\')){'."\n";
                $string .= "\t\t\t\t\t\t".'$arrwhere[\''.$v['columnenname'].'\'] = $this->request->post(\''.$v['columnenname'].'\');'."\n";
                $string .= "\t\t\t\t".'}'."\n";
            }        
            $string .= "\t\t\t\t".'if($this->request->get(\'tree\')){'."\n"; 
            $string .= "\t\t\t\t\t\t".'$llv = collection(model(\''.$mm['enname'].'\')->where($arrwhere)->order(\'createtime\', \'desc\')->select())->toArray();'."\n";
            $string .= "\t\t\t\t\t\t".'Tree::instance()->init($llv);'."\n";
            $string .= "\t\t\t\t\t\t".'$ll = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(\'\'), \'name\');'."\n";
            $string .= "\t\t\t\t".'}else{'."\n";
            $string .= "\t\t\t\t\t\t".'$ll = collection(model(\''.$mm['enname'].'\')->where($arrwhere)->order(\'createtime\',\'desc\')->select())->toArray();'."\n";
            $string .= "\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'for ($i=0; $i < count($ll); $i++) {'."\n";
            $string .= "\t\t\t\t\t\t".'if($ll[$i][\'itemid\']==$this->request->get(\'currentid\')){'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$ll[$i][\'selected\'] = 1;'."\n";
            $string .= "\t\t\t\t\t\t".'}else{'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'$ll[$i][\'selected\'] = 0;'."\n";
            $string .= "\t\t\t\t\t\t".'}'."\n";
            $string .= "\t\t\t\t".'}'."\n";

            $string .= "\t\t\t\t".'if(count($ll)>0){'."\n";
            // $string .= "\t\t\t\t\t\t".'foreach ($ll as $k => $v) {'."\n";
            // $string .= "\t\t\t\t\t\t\t\t".'$llary[$v[\'itemid\']][] = $v;'."\n";
            // $string .= "\t\t\t\t\t\t".'}'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'code\'] = 1;'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'message\'] = \'学校数据返回\';'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'data\'] = $ll;'."\n";
            $string .= "\t\t\t\t\t\t".'print_r(json_encode($ll));exit;'."\n";
            $string .= "\t\t\t\t".'}else{'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'code\'] = 0;'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'message\'] = \'无数据返回\';'."\n";
            // $string .= "\t\t\t\t\t\t".'$returnarry[\'data\'] = array();'."\n";
            $string .= "\t\t\t\t\t\t".'print_r(json_encode($ll));exit;'."\n";
            $string .= "\t\t\t\t".'}'."\n";      
            $string .= "\t\t".'}'."\n"; 
            $string .= "}\n";
            $string .= '?>'."\n";

            $filenamemodel = COMMON_PATH.DS.'model'.DS.ucfirst($name).'.php';
            
            $filenamecontroller = ADMIN_PATH.DS.'controller'.DS.($mm['dir']?$mm['dir'].DS:'').ucfirst($name).'.php';
            $result = file_put_contents($filenamemodel, $stringmodel);
            if(@$fpmodel = fopen($filenamemodel, 'wb')) {
                flock($fpmodel, LOCK_EX);
                $len = fwrite($fpmodel, $stringmodel);
                flock($fpmodel, LOCK_UN);
                fclose($fpmodel);
            }
            $result = file_put_contents($filenamecontroller, $string);
            if(@$fpcontroller = fopen($filenamecontroller, 'wb')) {
                flock($fpcontroller, LOCK_EX);
                $len = fwrite($fpcontroller, $string);
                flock($fpcontroller, LOCK_UN);
                fclose($fpcontroller);
                return 1;
            } else {
                return 0;
            }
        }
    }
    //生成建表语句
    public function makesql($name = ''){
        $database = config('database.database');
        $prefix = config('database.prefix');
        $table = $prefix.$name;
        $sql = 'CREATE TABLE `'.$table.'` ('."\n";
        $st = $this->with('columns')->where(['enname'=>$name])->find();
        
        $columntype = '';
        $carry = collection($st['columns'])->toArray();
        $flag = array();
        foreach($carry as $v){
            $flag[] = $v['listorder'];
        }
        array_multisort($flag, SORT_DESC,SORT_NUMERIC,$carry);
        foreach ($carry as $k => $v) {
            if($v['isintable']==1){
                switch ($v['columntype']) {
                    case 'identity':
                        $columntype = ' bigint(20) unsigned NOT NULL AUTO_INCREMENT ';
                    break;
                    case 'varcharlong':
                        $columntype = ' varchar(1000)  NOT NULL ';
                    break;
                    case 'varcharmid':
                        $columntype = ' varchar(400)  NOT NULL ';
                    break;
                    case 'varcharshort':
                        $columntype = ' varchar(100)  NOT NULL ';
                    break;
                    case 'guid':
                        $columntype = ' varchar(36)  NOT NULL ';
                    break;
                    case 'int':
                        $columntype = ' int(10)  NOT NULL ';
                    break;
                    case 'bigint':
                        $columntype = ' bigint(20)  NOT NULL ';
                    break;
                    case 'smallint':
                        $columntype = ' smallint(4)  NOT NULL ';
                    break;
                    case 'bool':
                        $columntype = ' tinyint(1)  NOT NULL ';
                    break;
                    case 'float':
                        $columntype = ' float(6,2)  NOT NULL ';
                    break;
                    case 'decimal':
                        $columntype = ' decimal(6,2)  NOT NULL ';
                    break;
                    case 'double':
                        $columntype = ' double(16,8)  NOT NULL ';
                    break;
                    case 'image':
                        $columntype = ' varchar(200)  NOT NULL ';
                    break;
                    case 'file':
                        $columntype = ' varchar(200)  NOT NULL ';
                    break;
                    case 'text':
                        $columntype = ' mediumtext ';
                    break;
                    case 'enum':
                        $columntype = ' enum ';
                    break;
                    default:
                    # code...
                    break;
                }
                $sql .= '`'.$v['columnenname'].'`';
                $sql .= $columntype.' COMMENT \''.$v['columnname'].'\''."\n";
                if($v['columnenname']!='itemid'){
                    if($v['default']){
                        $sql .= '  DEFAULT \''.$v['default'].'\', '."\n";
                    }else{
                        if(($v['columntype']=='int')||($v['columntype']=='bigint')||($v['columntype']=='smallint')||($v['columntype']=='bool')||($v['columntype']=='float')||($v['columntype']=='decimal')||($v['columntype']=='double')){
                            $sql .= '  DEFAULT \'0\', '."\n";
                        }else{
                            if($v['columntype']!='text'){
                                $sql .= '  DEFAULT \'\', '."\n";
                            }else{
                                $sql .= ',';
                            }

                        }
                    }
                }else{
                    $sql .= ','."\n";
                }
            }
        }
        $sql .= 'PRIMARY KEY (`itemid`)'."\n";
        $sql .= ') ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT=\'\';';
        //print_r($sql);die;
        db()->execute('DROP TABLE IF EXISTS `'.$table.'`;');
        db()->execute($sql);
        //$pdo->exec($sql);
        //db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
    }

    public function makeaddtemplate($name = ''){
        if($name){
            $ll = Cols::columnread($name);
            $m = $this->get(['enname'=>$name]);
            $mpid = $this->get($m['pid']);
			$dir = '';
			if($m['dir']){
				$dir = ADMIN_PATH.DS.'view'.DS.$m['dir'].DS;
				if(!is_dir($dir)){
					mkdir($dir);
				}
			}
            $dir = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS;
            if(!is_dir($dir)){
                mkdir($dir);
            }
            $lls = array();
            $string = '<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">'."\n";
            foreach ($ll as $k => $v) {
                //如果是关联其他模型，检测一下，模型是否是强关联。
                if($m['pid']&&($v['rname']==$mpid['enname'])){
                    $string .= "\t\t".'<input type="hidden" id="c-'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$'.$v['columnenname'].'}" />'."\n";
                }else{
                    if($v['isshowadd']==1){
                        $string .= "\t\t".'<div class="form-group">'."\n";
                        $string .= "\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                        $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";

                        switch ($v['optionform']) {
                            case 'select':
                                $string .= "\t\t\t\t\t\t".'<select id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" name="row['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                                $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'" '.($v['optiondepend']?'datarelate="'.$v['optiondepend'].'"':'').'>'."\n";
                                if($v['options']){
                                    $string .= "\t\t\t\t\t\t\t\t".'<option value="">请选择</option>';
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'">'.$vv.'</option>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</select>'."\n";
                            break;
                            case 'radio':
                                $string .= "\t\t\t\t\t\t".'<div class="radio" for="'.$v['columnenname'].'" '.($v['optionurl']?' dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    $arr = array();
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                                        $string .= '<input name="row['.$v['columnenname'].']" type="radio" value="'.$kk.'" ';

                                        $string .= (($v['default']==$kk)?'checked="checked"':'');
                                        $string .= ' /> '.$vv.'</label>'."\n";

                                    }
                                }

                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'checkbox':
                                $string .= "\t\t\t\t\t\t".'<div class="checkbox" for="'.$v['columnenname'].'" '.($v['optionurl']?' dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    $arr = array();
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'"><input name="row['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" /> '.$vv.'</label>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'select3':
                                $string .= "\t\t\t\t\t\t".'<div class="selects3" data-pid="'.$m['catid'].'" data-multiple="0">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">请选择</span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'select4':
                                $string .= "\t\t\t\t\t\t".'<div class="selects3" data-pid="'.$m['catid'].'" data-multiple="1">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">请选择</span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'text':
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">';
                                    $string .= "\t\t\t\t\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'image':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="false" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;

                            case 'file':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="application/msword,application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/zip" data-multiple="false"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'multiimage':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="true" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;
                            case 'datetime':
                                $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control datetimepicker" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                            break;
                            case 'upyunimage':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="" />';
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                            break;
                            case 'upyunfile':
                                $string .= "";                                    
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.txt.ppt,.pptx" tabindex="-1"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'upyunimagemulti':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="" />';
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="true">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                            break;
                            case 'openwindow':
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="c-'.$v['columnenname'].'" class="btn btn-openwindow" data-multiple="'.($v['relate']<3?'0':'1').'" data-input-id="'.$v['columnenname'].'">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-search-plus"></i> '.$v['columnname']."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" id="'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";

                                $columnlistwindow = model('Column')->getColumnsByShowwindow($v['rname']);
                                foreach ($columnlistwindow as $k2 => $v2) {
                                    if($v2['columnenname']!='itemid'){
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<label id="'.$v['rname'].$v2['columnenname'].'"></label>'."\n";
                                    }                                        
                                }                                    
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            default:
                                if($v['columntype']=='text'){
                                    $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote"></textarea>'."\n";
                                }elseif($v['columntype']=='varcharlong'){
                                    $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control"></textarea>'."\n";
                                }else{
                                    $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control" name="row['.$v['columnenname'].']" type="'.(($v['columntype']=='int'||$v['columntype']=='smallint')?'number':'text').'" value="" />'."\n";
                                }
                            break;
                        }
                        $string .= "\t\t\t\t".'</div>'."\n";
                        $string .= "\t\t".'</div>'."\n";
                    }
                }
                
            }
            $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
                $string .= "\t\t\t\t\t\t".'<label class="control-label col-xs-12 col-sm-2"></label>'."\n";
                $string .= "\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'<button type="submit" class="btn btn-success btn-embossed">'.__('OK').'</button>'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'<button type="reset" class="btn btn-default btn-embossed">'.__('Reset').'</button>'."\n";
            $string .= "\t\t\t\t\t\t".'</div>'."\n";
            $string .= "\t\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</form>';
            $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'add.html';
            //$filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').'add.html';
            $result = file_put_contents($filename, $string);
            if(@$fp = fopen($filename, 'wb')) {
                flock($fp, LOCK_EX);
                $len = fwrite($fp, $string);
                flock($fp, LOCK_UN);
                fclose($fp);
                return 1;
            } else {
                return 0;
            }
        }
    }

    public function makeedittemplate($name = ''){
        if($name){
            $ll = Cols::columnread($name);
            $m = $this->get(['enname'=>$name]);
            $mpid = $this->get($m['pid']);
            $dir = '';
			if($m['dir']){
				$dir = ADMIN_PATH.DS.'view'.DS.$m['dir'].DS;
				if(!is_dir($dir)){
					mkdir($dir);
				}
			}
            $dir = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS;
            if(!is_dir($dir)){
                mkdir($dir);
            }
            $lls = array();
            $string = '<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">'."\n";
            foreach ($ll as $k => $v) {
                
                if($m['pid']&&($v['rname']==$mpid['enname'])){
                    $string .= "\t\t".'<input type="hidden" id="c-'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$row.'.$v['columnenname'].'}" />'."\n";
                }else{
                    if($v['isshowedit']==1){
                        $string .= "\t\t".'<div class="form-group">'."\n";
                        $string .= "\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                        $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                        switch ($v['optionform']) {
                            case 'select':
                                $string .= "\t\t\t\t\t\t".'<select id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" name="row['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                                $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'" '.($v['optiondepend']?'datarelate="'.$v['optiondepend'].'"':'');
                                $string .= ($v['optionurl']?' currentid="{$row.'.$v['columnenname'].'}"':'').">\n";
                                if($v['options']&&!$v['optionurl']){
                                    $string .= '<option value="">请选择</option>'."\n";
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}>'.$vv.'</option>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</select>'."\n";
                            break;
                            case 'radio':
                                $string .= "\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'checkbox':
                                $string .= "\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'select3':
                                $string .= "\t\t\t\t\t\t".'<div class="selects3" data-pid="{$row.catid}" data-multiple="0">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">{$row.category.name}</span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="{$row.catid}" />'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'select4':
                                $string .= "\t\t\t\t\t\t".'<div class="selects3" data-pid="'.$m['catid'].'" data-multiple="1">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">请选择</span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'text':
                                $string .= "\t\t\t\t\t\t".'<div class="form-group">';
                                    $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>';
                                $string .= "\t\t\t\t\t\t".'</div>';
                            break;
                            case 'image':
                              $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="false" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                              $string .= "\t\t\t\t\t\t".'</div>'."\n";
                              $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;
                            case 'file':
                                $string .= "\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                          $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="application/msword,application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/zip" data-multiple="false"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'multiimage':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="true" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;
                            case 'datetime':
                              $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control datetimepicker" name="row['.$v['columnenname'].']" type="text" value="<?php echo \fast\Date::timetodate($row[\''.$v['columnenname'].'\'],5);?>" />'."\n";
                            break;
                            case 'upyunimage':
                                // $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>"'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />';
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                // $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'upyunimagemulti':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />';
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="true">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                            break;
                            case 'upyunfile':
                                $string .= "";
                                // $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">打包文件:</label>'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.txt.ppt,.pptx" tabindex="-1"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                //$string .= "\t\t\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                // $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                          case 'openwindow':
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="c-'.$v['columnenname'].'" class="btn btn-openwindow" data-multiple="'.($v['relate']<3?'0':'1').'" data-input-id="'.$v['columnenname'].'">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-search-plus"></i> '.$v['columnname']."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" id="'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<label>{$'.$v['rname'].'str}</label>'."\n";
                                /*
                                $columnlistwindow = model('Column')->getColumnsByShowwindow($v['rname']);
                                foreach ($columnlistwindow as $k2 => $v2) {
                                    if($v2['columnenname']!='itemid'){
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<label id="'.$v['rname'].$v2['columnenname'].'"></label>'."\n";
                                    }                                        
                                } 
                                */                                   
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                          break;
                          default:
                            if($v['columntype']=='text'){
                                $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                            }elseif($v['columntype']=='varcharlong'){
                                $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                            }else{
                                $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control" name="row['.$v['columnenname'].']" type="'.(($v['columntype']=='int'||$v['columntype']=='smallint')?'number':'text').'" value="{$row.'.$v['columnenname'].'|htmlspecialchars}" />'."\n";
                            }
                          break;
                        }
                        $string .= "\t\t\t\t".'</div>'."\n";
                        $string .= "\t\t".'</div>'."\n";
                    }
                }
            }
            $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'<label class="control-label col-xs-12 col-sm-2"></label>'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="submit" class="btn btn-success btn-embossed">'.__('OK').'</button>'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="reset" class="btn btn-default btn-embossed">'.__('Reset').'</button>'."\n";
            $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
            $string .= "\t\t\t\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</form>'."\n";
            $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'edit.html';
            $result = file_put_contents($filename, $string);
            if(@$fp = fopen($filename, 'wb')) {
                flock($fp, LOCK_EX);
                $len = fwrite($fp, $string);
                flock($fp, LOCK_UN);
                fclose($fp);
                //return 1;
            } else {
                //return 0;
            }
            $string = '<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">'."\n";
            $rname = '';
            foreach ($ll as $k => $v) {
                
                if($m['pid']&&($v['rname']==$mpid['enname'])){
                    $rname = $v['rname'];
                    $string .= "\t\t".'<input type="hidden" id="c-'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$'.$v['columnenname'].'}" />'."\n";
                }else{
                    if($v['isshowedit']==1){
                        $string .= "\t\t".'<div class="form-group">'."\n";
                        $string .= "\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                        $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                        switch ($v['optionform']) {
                            case 'select':
                                $string .= "\t\t\t\t\t\t".'<select id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" name="row['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                                $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'" '.($v['optiondepend']?'datarelate="'.$v['optiondepend'].'"':'');
                                $string .= ($v['optionurl']?' currentid="{$row.'.$v['columnenname'].'}"':'').">\n";
                                if($v['options']&&!$v['optionurl']){
                                    $string .= '<option value="">请选择</option>'."\n";
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}>'.$vv.'</option>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</select>'."\n";
                            break;
                            case 'radio':
                                $string .= "\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'checkbox':
                                $string .= "\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                                if($v['options']){
                                    $arr2 = json_decode($v['options'],TRUE);
                                    foreach ($arr2 as $kk => $vv) {
                                        $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                    }
                                }
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'select3':
                                $string .= "\t\t\t\t\t\t".'<div class="selects3" data-pid="{$row.catid}">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">{$row.category.name}</span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="{$row.catid}" />'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'text':
                                $string .= "\t\t\t\t\t\t".'<div class="form-group">';
                                    $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>';
                                $string .= "\t\t\t\t\t\t".'</div>';
                            break;
                            case 'image':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="false" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;
                            case 'file':
                                $string .= "\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                          $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="application/msword,application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/zip" data-multiple="false"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'multiimage':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/webp" data-multiple="true" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                            break;
                            case 'datetime':
                              $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control datetimepicker" name="row['.$v['columnenname'].']" type="text" value="<?php echo \fast\Date::timetodate($row[\''.$v['columnenname'].'\'],5);?>" />'."\n";
                            break;
                            case 'upyunimage':
                                // $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>"'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />';
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                // $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'upyunimagemulti':
                                $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />';
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="true">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".gif,.jpg,.jpeg,.tiff" tabindex="-1" previewid="p-'.$v['columnenname'].'"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                            break;
                            case 'upyunfile':
                                $string .= "";
                                // $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">打包文件:</label>'."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="plupload-image'.$v['columnenname'].'" class="btn btn-danger" data-input-id="c-'.$v['columnenname'].'" data-multiple="false">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-upload"></i> {:__(\'Upload\')}'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="moxie-shim-html5">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="upyun_upload'.$v['columnenname'].'" class="upyun_upload" type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.txt.ppt,.pptx" tabindex="-1"/>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                //$string .= "\t\t\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul> '."\n";
                                // $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                                // $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            case 'openwindow':
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="button" id="c-'.$v['columnenname'].'" class="btn btn-openwindow" data-multiple="'.($v['relate']<3?'0':'1').'" data-input-id="'.$v['columnenname'].'">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<i class="fa fa-search-plus"></i> '.$v['columnname']."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'</button>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" id="'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$row.'.$v['columnenname'].'}" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<label>{$'.$v['rname'].'str}</label>'."\n";
                                /*
                                $columnlistwindow = model('Column')->getColumnsByShowwindow($v['rname']);
                                foreach ($columnlistwindow as $k2 => $v2) {
                                    if($v2['columnenname']!='itemid'){
                                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<label id="'.$v['rname'].$v2['columnenname'].'"></label>'."\n";
                                    }                                        
                                } 
                                */                                   
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                            break;
                            default:
                                if($v['columntype']=='text'){
                                    $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                                }elseif($v['columntype']=='varcharlong'){
                                    $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                                }else{
                                    $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control" name="row['.$v['columnenname'].']" type="'.(($v['columntype']=='int'||$v['columntype']=='smallint')?'number':'text').'" value="{$row.'.$v['columnenname'].'|htmlspecialchars}" />'."\n";
                                }
                            break;
                        }
                        $string .= "\t\t\t\t".'</div>'."\n";
                        $string .= "\t\t".'</div>'."\n";
                    }
                }
                
            }     
            $string .= "\t\t".'<div class="form-group">'."\n";
            $string .= "\t\t\t\t".'<label class="control-label col-xs-12 col-sm-2"></label>'."\n";
            $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
            $string .= "\t\t\t\t\t\t".'<button type="submit" class="btn btn-success btn-embossed">确定</button>'."\n";
            $string .= "\t\t\t\t\t\t".'<button type="reset" class="btn btn-default btn-embossed">重置</button>'."\n";
            $string .= "\t\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</div>'."\n";
            $string .= '</form>'."\n";
            $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'editby'.$rname.'.html';
            $result = file_put_contents($filename, $string);
            if(@$fp = fopen($filename, 'wb')) {
                flock($fp, LOCK_EX);
                $len = fwrite($fp, $string);
                flock($fp, LOCK_UN);
                fclose($fp);
                //return 1;
            } else {
                //return 0;
            }    
            
        }
    }

    public function makelisttemplate($name = ''){
        if($name){
            $ll = Cols::columnread($name);
            $flag = array();
            foreach($ll as $v){
              $flag[] = $v['listorder'];
            }
            array_multisort($flag, SORT_DESC, $ll);
            $m = $this->get(['enname'=>$name]);
            $dir = '';
			if($m['dir']){
				$dir = ADMIN_PATH.DS.'view'.DS.$m['dir'].DS;
				if(!is_dir($dir)){
					mkdir($dir);
				}
			}
            $dir = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS;
            if(!is_dir($dir)){
                mkdir($dir);
            }
            $lls = array();
            $string = '<div class="panel panel-default panel-intro">'."\n";
            $string .= "\t".'<div class="panel-body">'."\n";
            $string .= "\t\t".'<div id="myTabContent" class="tab-content">'."\n";
            $string .= "\t\t\t".'<div class="tab-pane fade active in" id="one">'."\n";
            $string .= "\t\t\t".'<div class="widget-body no-padding">'."\n";
            $string .= "\t\t\t".'<div class="bootstrap-table">'."\n";
            $string .= "\t\t\t\t".'<div class="commonsearch-table">'."\n";
            $string .= "\t\t\t\t\t".'<form class="form-horizontal form-commonsearch" action="" method="get">'."\n";
            $string .= "\t\t\t\t\t".'<fieldset>'."\n";
            $string .= "\t\t\t\t\t".'<div class="row">'."\n";
            foreach ($ll as $k => $v) {
              if(($v['isshowsearch']==1)&&($v['rname']=='')){
                $string .= "\t\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
                $string .= "\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'" class="control-label col-xs-4">'.$v['columnname'].'</label>'."\n";
                $string .= "\t\t\t\t\t\t".'<div class="col-xs-8">'."\n";
                switch ($v['optionform']) {
                    case 'select':
                        $string .= '<select id="s-'.$v['columnenname'].'" name="search['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                        $string .= ' class="form-control selectpickernew">'."\n";
                        if($v['options']){
                            $string .= '<option value="0">请选择</option>'."\n";
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if isset($'.$v['columnenname'].')}{if $'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}{/if}>'.$vv.'</option>'."\n";
                            }
                        }
                        $string .= '</select>'."\n";
                    break;
                    case 'radio':
                        $string .= "\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                        if($v['options']){
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                                $string .= "\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                            }
                        }
                        $string .= "\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'check':
                        $string .= "\t\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                        if($v['options']){
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                            }
                        }
                        $string .= "\t\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'select3':
                        $string .= "\t\t\t\t\t\t\t".'<div class="selects3" data-pid="{$catid??\'0\'}" data-multiple="0">'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">类别名称</span>';
                          $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="search[catid]" value="{$catid??\'0\'}" />'."\n";
                        $string .= "\t\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'select4':
                        $string .= "\t\t\t\t\t\t\t".'<div class="selects3" data-pid="{$catid??\'0\'}" data-multiple="1">'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">类别名称</span>';
                          $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="search[catid]" value="{$catid??\'0\'}" />'."\n";
                        $string .= "\t\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'datetime':
                      $string .= "\t\t\t\t\t\t\t".'<input type="text" class="form-control datetimepicker" name="search['.$v['columnenname'].']" value="<?php echo \fast\Date::timetodate($'.$v['columnenname'].',3); ?>" placeholder="'.$v['columnname'].'??\'\'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                    break;
                    default:
                      $string .= "\t\t\t\t\t\t\t".'<input type="text" class="form-control" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" placeholder="'.$v['columnname'].'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                      break;
                }
                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                $string .= "\t\t\t\t".'</div>'."\n";
              }
            }

            $string .= "\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
            $string .= "\t\t\t\t\t\t".'<div class="col-sm-8 col-xs-offset-4 text-center">'."\n";
            foreach ($ll as $k => $v) {
                if(($v['isshowsearch']==1)&&($v['rname']!='')){
                    $string .= "\t\t\t\t\t\t".'<input type="hidden" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" />'."\n";
                }
            }
            $string .= "\t\t\t\t\t\t".'<input type="hidden" name="offset" value="{$offset}" />'."\n";
            $string .= "\t\t\t\t\t\t".'<input type="hidden" name="limit" value="{$limit}" />'."\n";
            $string .= "\t\t\t\t\t\t".'<button type="submit" class="btn btn-success">搜索</button>'."\n";
            $string .= "\t\t\t\t\t\t".'<button type="reset" class="btn btn-default">重置</button>'."\n";
            $string .= "\t\t\t\t\t\t".'</div>'."\n";
            $string .= "\t\t\t\t".'</div>'."\n";
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t\t".'</fieldset>'."\n";
            $string .= "\t\t".'</form>'."\n";
            $string .= "\t".'</div>'."\n";

            $string .= "\t".'<div class="fixed-table-toolbar">'."\n";
            $string .= "\t\t".'<div class="bs-bars pull-left">'."\n";
            $string .= "\t\t\t".'<div id="toolbar" class="toolbar" style="position: relative;">'."\n";
            $string .= "\t\t\t\t".'<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新">';
            $string .= "\t\t\t\t".'<i class="fa fa-refresh"></i></a>'."\n";
            $string .= "\t\t\t\t".'<a href="javascript:;" url="'.($m['dir']?$m['dir'].'.':'').$name.'/add';
            if($m['pid']!=''){
                $sc = '';
                foreach ($ll as $k => $v) {
                    if($v['rname']!=''){
                        $sc = $v['columnenname'];
                    }
                }
                $string .= '?'.$sc.'=<?php echo !empty($'.$sc.')?$'.$sc.':0; ?>';
            }
            $string .= '" class="btn btn-success btn-add thisaddtabs" title="添加">';
            $string .= "\t\t\t\t".'<i class="fa fa-plus"></i> 添加</a>'."\n";
            $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled" title="编辑"><i class="fa fa-pencil"></i> 编辑</a>'."\n";
            $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled" title="删除"><i class="fa fa-trash"></i>删除</a>'."\n";
            $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-danger btn-import" title="导入" id="btn-import-GlaqcJ" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false" initialized="true" style="position: relative; z-index: 1;"><i class="fa fa-upload"></i> 导入</a>'."\n";
            //在有状态status字段的情况下，有状态设置按钮
            if(array_key_exists('Status', $ll)){
                $string .= "\t\t\t\t".'<div class="dropdown btn-group ">'."\n";
                $string .= "\t\t\t\t".'<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> 设置</a>'."\n";
                $string .= "\t\t\t\t\t".'<ul class="dropdown-menu text-left" role="menu">'."\n";
                if($ll['Status']['options']){
                    $llary = json_decode($ll['Status']['options'],TRUE);
                    foreach ($llary as $kk => $vv) {
                        $string .= "\t\t\t\t\t\t".'<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status='.$kk.'"><i class="fa"></i> '.$vv.'</a></li>'."\n";
                    }
                }
                $string .= "\t\t\t\t\t".'</ul>'."\n";
                $string .= "\t\t\t\t".'</div>'."\n";
            }
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</div>'."\n";
            $string .= "\t\t".'<div class="columns columns-right btn-group pull-right">'."\n";
            $string .= "\t\t\t".'<button class="btn btn-default" type="button" id="toggleview" name="toggleview" aria-label="toggle" title="切换">'."\n";
            $string .= "\t\t\t\t".'<i class="glyphicon glyphicon-list-alt icon-list-alt"></i>'."\n";
            $string .= "\t\t\t".'</button>'."\n";
            $string .= "\t\t\t".'<div class="keep-open btn-group" title="列">'."\n";
            $string .= "\t\t\t\t".'<button type="button" aria-label="columns" class="btn btn-default dropdown-toggle" data-toggle="dropdown">'."\n";
            $string .= "\t\t\t\t".'<i class="glyphicon glyphicon-th icon-th"></i><span class="caret"></span></button>'."\n";
            $string .= "\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
            $string .= "\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $string .= "\t\t\t\t\t\t\t".'{if $v.columnenname!=\'itemid\'}'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t".'<li role="menuitem" class="cheng_showlist"><label>'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t".'<input type="checkbox" data-field="{$v.columnenname}" value="{$v.itemid}" {if $v.isshowlist==1}checked="checked"{/if} />{$v.columnname}'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t".'</label></li>'."\n";
            $string .= "\t\t\t\t\t\t\t".'{/if}'."\n";
            $string .= "\t\t\t\t\t".'{/volist}'."\n";
            /*
            foreach ($ll as $k => $v) {
              $string .= "\t\t\t\t".'<li role="menuitem" class="cheng_showlist"><label>'."\n";
              $string .= "\t\t\t\t".'<input type="checkbox" data-field="'.$v['columnenname'].'" value="'.$v['itemid'].'" '.($v['isshowlist']?'checked="checked"':'').' />'.$v['columnname']."\n";
              $string .= "\t\t\t\t".'</label></li>'."\n";
              //if($v['isshowlist']==1){}
            }
            */
            $string .= "\t\t\t".'</ul>'."\n";
            $string .= "\t\t".'</div>'."\n";
            $string .= "\t\t".'<div class="export btn-group">'."\n";
            $string .= "\t\t\t".'<button class="btn btn-default dropdown-toggle" aria-label="export type" title="导出数据" data-toggle="dropdown" type="button"><i class="glyphicon glyphicon-export icon-share"></i> <span class="caret"></span></button>'."\n";
            $string .= "\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="json"><a href="javascript:void(0)">JSON</a></li>'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="xml"><a href="javascript:void(0)">XML</a></li>'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="csv"><a href="javascript:void(0)">CSV</a></li>'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="txt"><a href="javascript:void(0)">TXT</a></li>'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="doc"><a href="javascript:void(0)">MS-Word</a></li>'."\n";
            $string .= "\t\t\t\t".'<li role="menuitem" data-type="excel"><a href="javascript:void(0)">MS-Excel</a></li>'."\n";
            $string .= "\t\t\t".'</ul>'."\n";
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</div>'."\n";

            $string .= "\t".'<div class="fixed-table-container">'."\n";
            $string .= "\t\t".'<div class="fixed-table-body">'."\n";
            $string .= "\t\t".'<table id="table" class="table table-striped table-bordered table-hover" data-operate-edit="1" data-operate-del="1" width="100%">'."\n";
            $string .= "\t\t\t".'<thead>'."\n";
            $string .= "\t\t\t\t".'<tr>'."\n";
            $string .= "\t\t\t\t\t".'<th class="bs-checkbox" data-field="0">'."\n";
            $string .= "\t\t\t\t\t".'<div class="th-inner"><input id="chkSelectAll" name="chkSelectAll" type="checkbox" /></div>'."\n";
            $string .= "\t\t\t\t\t".'<div class="fht-cell"></div>'."\n";
            $string .= "\t\t\t\t\t".'</th>'."\n";
            /*
            foreach ($ll as $k => $v) {
              if(($v['isshowlist']==1)&&($v['columnenname']!='itemid')){
                  $string .= "\t\t\t\t\t".'<th data-field="'.$v['columnenname'].'">'."\n";
                  $string .= "\t\t\t\t\t".'<div class="th-inner">'.$v['columnname'].'</div><div class="fht-cell"></div>'."\n";
                  $string .= "\t\t\t\t\t".'</th>'."\n";
              }
            }
            */
            $string .= "\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $string .= "\t\t\t\t\t\t\t".'{if condition="($v.isshowlist==1) and ($v.columnenname!=\'itemid\')"}'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t".'<th data-field="{$v.columnenname}">'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t\t\t".'<div class="th-inner">{$v.columnname}</div><div class="fht-cell"></div>'."\n";
            $string .= "\t\t\t\t\t\t\t\t\t".'</th>'."\n";
            $string .= "\t\t\t\t\t\t\t".'{/if}'."\n";
            $string .= "\t\t\t\t\t".'{/volist}'."\n";
            $string .= "\t\t\t\t\t".'<th data-field="operate"><div class="th-inner">操作</div>'."\n";
            $string .= "\t\t\t\t\t".'<div class="fht-cell"></div>'."\n";
            $string .= "\t\t\t\t\t".'</th>'."\n";
            $string .= "\t\t\t\t".'</tr>'."\n";
            $string .= "\t\t\t".'</thead>'."\n";
            $string .= "\t\t\t".'<tbody data-listidx="0" id="datalist">'."\n";
            $string .= "\t\t\t\t".'{volist name="lists" id="vo" key="k"}'."\n";
            $string .= "\t\t\t\t".'<tr data-index="{$k}">'."\n";
            $string .= "\t\t\t\t\t".'<td class="bs-checkbox" columnname="itemid">'."\n";
            $string .= "\t\t\t\t\t".'<input data-index="{$k}" name="btSelectItem" type="checkbox" value="{$vo.itemid}" /></td>'."\n";

            $string .= "\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $string .= "\t\t\t\t\t".'{if condition="($v.isshowlist==1) and ($v.columnenname!=\'itemid\')"}'."\n";
            $string .= "\t\t\t\t\t".'<td columnname="{$v.columnenname|ucfirst}">{$vo[$v.columnenname]}</td>'."\n";
            $string .= "\t\t\t\t\t".'{/if}'."\n";
            $string .= "\t\t\t\t".'{/volist}'."\n";
            $string .= "\t\t\t\t\t".'<td columnname="caozuo">'."\n";
            $strs = '';
            $mplist = $this->getModelByPid($m['itemid']);
            
            foreach ($mplist as $k => $v) {
                $strs .= '<a href="javascript:;" url="';
                
                $llm = model('Column')->getColumnsByRelation($m['enname']);
                //print_r($llm);exit;
                foreach($llm as $kk=>$vv){
                    $item = $this->get($vv['moduleid']);
                    if($item['pid']==$m['itemid']){
                        if($vv['relate']==1){
                            $strs .= '/cms.php/'.($v['dir']?$v['dir'].'.':'').$v['enname'].'/editby'.$m['enname'].'?dialog=1&amp;'.$m['enname'].'id={$vo.itemid}" class="btn btn-xs btn-primary btn-openwindow"';
                            $strs .= ' title=""><i class="fa fa-cubes"></i>查看'.$v['name'].'</a>&nbsp;';
                            //$strs .= 'search['.$vv['columnenname'].']={$vo.itemid}" class="btn btn-xs btn-primary thisaddtabs" title="查看'.$v['name'].'"><i class="fa fa-cubes"></i>查看'.$v['name'].'</a>&nbsp;';
                        }
                        if($vv['relate']==2){
                            $strs .= '/cms.php/'.($v['dir']?$v['dir'].'.':'').$v['enname'].'/index?dialog=1&amp;';
                            $strs .= 'search['.$vv['columnenname'].']={$vo.itemid}" class="btn btn-xs btn-primary thisaddtabs" title="查看'.$v['name'].'"><i class="fa fa-cubes"></i>查看'.$v['name'].'</a>&nbsp;';
                        }
                        
                    }
                }
            }
            //<a href="javascript:;" url="/cms.php/school/student/index?dialog=1&amp;search[classid]={$vo.itemid}" class="btn btn-xs btn-primary thisaddtabs" title="查看学生"><i class="fa fa-cubes"></i>查看学生</a>
            $string .= "\t\t\t\t\t\t".$strs."\n";
            $string .= "\t\t\t\t\t\t".'<a href="javascript:;" url="/cms.php/'.($m['dir']?$m['dir'].'.':'').$name.'/edit?dialog=1&amp;ids={$vo.itemid}" class="btn btn-xs btn-success btn-editone thisaddtabs" title="编辑'.$m['name'].'"><i class="fa fa-pencil"></i></a>&nbsp;'."\n";
            $string .= "\t\t\t\t\t\t".'<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="{$vo.itemid}"><i class="fa fa-trash"></i></a>'."\n";
            $string .= "\t\t\t\t\t".'</td>'."\n";
            $string .= "\t\t\t\t".'</tr>'."\n";
            $string .= "\t\t\t".'{/volist}'."\n";
            $string .= "\t\t".'</tbody>'."\n";
            $string .= "\t\t".'</table>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t\t\t".'<div class="fixed-table-footer" style="display: none;">'."\n";
            $string .= "\t\t\t\t".'<table><tbody><tr></tr></tbody></table>'."\n";
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t\t".'<div class="fixed-table-pagination" style="display: block;">'."\n";
            $string .= "\t\t\t\t".'<div class="pull-left pagination-detail">'."\n";
            $string .= "\t\t\t\t".'<span class="pagination-info">'."\n";
            $string .= "\t\t\t\t".'显示第 {$offset+1} 到第 {if $totalpage eq $page}{$total}{else}{$limit*$page}{/if} 条记录，总共 {$total} 条记录</span>'."\n";
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t\t".'<div class="pull-right pagination">'."\n";
            $string .= "\t\t\t\t".'<ul class="pagination">'."\n";
            $string .= "\t\t\t\t".'{if $page eq 1 || $offset eq 0 }'."\n";
            $string .= "\t\t\t\t\t".'<li class="page-pre"><a href="#" class="btn-disabled disabled">上一页</a></li>'."\n";
            $string .= "\t\t\t\t".'{else}'."\n";
            $string .= "\t\t\t\t\t".'<li class="page-pre"><a href="{$surl}&offset={$offset-$limit}">上一页</a></li>'."\n";
            $string .= "\t\t\t\t".'{/if}'."\n";
            $string .= "\t\t\t\t".'{for start="1" end="($totalpage+1)"}'."\n";
            $string .= "\t\t\t\t\t".'<li class="page-number {if $i eq $page}active{/if}">'."\n";
            $string .= "\t\t\t\t\t".'<a href="{$surl}&offset={$limit*($i-1)}">{$i}</a></li>'."\n";
            $string .= "\t\t\t\t".'{/for}'."\n";
            $string .= "\t\t\t\t".'{if $page < $totalpage}'."\n";
            $string .= "\t\t\t\t\t".'<li class="page-next"><a href="{$surl}&offset={$offset+$limit}">下一页</a></li>'."\n";
            $string .= "\t\t\t\t".'{else}'."\n";
            $string .= "\t\t\t\t\t".'<li class="page-next"><a href="#">下一页</a></li>'."\n";
            $string .= "\t\t\t\t".'{/if}'."\n";
            $string .= "\t\t\t\t".'</ul>'."\n";
            $string .= "\t\t\t".'</div>'."\n";
            $string .= "\t\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div><div class="clearfix"></div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= "\t".'</div>'."\n";
            $string .= '<script type="text/javascript">'."\n";
            $string .= 'var pagedata = {'."\n";
            $string .= "\t\t".'list: {$listsjson|raw},'."\n";
            $string .= "\t\t".'columns:{$columnlistjson|raw}'."\n";
            $string .= '};'."\n";
            $string .= '</script>'."\n";
            $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'index.html';
            $filenameselect = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'select.html';

            $stringselect = '<div class="panel panel-default panel-intro">'."\n";
            $stringselect .= "\t\t".'<div class="panel-body">'."\n";
            $stringselect .= "\t\t\t\t".'<div id="myTabContent" class="tab-content">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<div class="tab-pane fade active in" id="one">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<div class="widget-body no-padding">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'<div class="bootstrap-table">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="commonsearch-table">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<form class="form-horizontal form-commonsearch" action="" method="get">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<fieldset>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="row">'."\n";
            foreach ($ll as $k => $v) {
                  if(($v['isshowsearch']==1)&&($v['rname']=='')){
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'" class="control-label col-xs-4">'.$v['columnname'].'</label>'."\n";
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="col-xs-8">'."\n";
                    switch ($v['optionform']) {
                        case 'select':
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<select id="s-'.$v['columnenname'].'" name="search['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                            $stringselect .= ' class="form-control selectpickernew">'."\n";
                            if($v['options']){
                                $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="0">请选择</option>'."\n";
                                $arr2 = json_decode($v['options'],TRUE);
                                foreach ($arr2 as $kk => $vv) {
                                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if isset($'.$v['columnenname'].')}{if $'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}{/if}>'.$vv.'</option>'."\n";
                                }
                            }
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</select>'."\n";
                        break;
                        case 'radio':
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                            if($v['options']){
                                $arr2 = json_decode($v['options'],TRUE);
                                foreach ($arr2 as $kk => $vv) {
                                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                }
                            }
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                        break;
                        case 'check':
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                            if($v['options']){
                                $arr2 = json_decode($v['options'],TRUE);
                                foreach ($arr2 as $kk => $vv) {
                                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                                }
                            }
                            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                        break;
                        case 'select3':
                          $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="selects3" data-pid="{$catid??\'0\'}">'."\n";
                              $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="/assets/img/arrow_bottom1.png" /></a>'."\n";
                              $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<span class="selected3">类别名称</span>';
                              $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="search[catid]" value="{$catid??\'0\'}" />'."\n";
                          $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                        break;
                        case 'datetime':
                          $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="text" class="form-control datetimepicker" name="search['.$v['columnenname'].']" value="<?php echo \fast\Date::timetodate($'.$v['columnenname'].',3); ?>" placeholder="'.$v['columnname'].'??\'\'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                        break;
                        default:
                          $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="text" class="form-control" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" placeholder="'.$v['columnname'].'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                          break;
                    }
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                  }
            }
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="col-sm-8 col-xs-offset-4 text-center">'."\n";
            foreach ($ll as $k => $v) {
                if(($v['isshowsearch']==1)&&($v['rname']!='')){
                    $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" />'."\n";
                }
            }
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" name="offset" value="{$offset}" />'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="hidden" name="limit" value="{$limit}" />'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="submit" class="btn btn-success">搜索</button>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<button type="reset" class="btn btn-default">重置</button>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'</fieldset>'."\n";
            $stringselect .= "\t\t\t\t".'</form>'."\n";
            $stringselect .= "\t\t".'</div>'."\n";
            $stringselect .= "\t\t".'<div class="fixed-table-toolbar">'."\n";
            $stringselect .= "\t\t\t\t".'<div class="bs-bars pull-left">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<div id="toolbar" class="toolbar" style="position: relative;">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新"><i class="fa fa-refresh"></i></a>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<a class="btn btn-danger btn-choose-multi disabled"><i class="fa fa-check"></i> {:__(\'Choose\')}</a>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'<div class="columns columns-right btn-group pull-right">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<button class="btn btn-default" type="button" id="toggleview" name="toggleview" aria-label="toggle" title="切换"><i class="glyphicon glyphicon-list-alt icon-list-alt"></i></button>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<div class="keep-open btn-group" title="列">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<button type="button" aria-label="columns" class="btn btn-default dropdown-toggle" data-toggle="dropdown">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<i class="glyphicon glyphicon-th icon-th"></i><span class="caret"></span></button>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{if $v.columnenname!=\'itemid\'}'."\n";     
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<li role="menuitem" class="cheng_showlist"><label>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input type="checkbox" data-field="{$v.columnenname}" value="{$v.itemid}" {if $v.isshowwindow==1}checked="checked"{/if} />{$v.columnname}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</label></li>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{/volist}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'</ul>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'</div>'."\n";                                  
            $stringselect .= "\t\t\t\t".'<div class="fixed-table-container">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<div class="fixed-table-body">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<table id="table" class="table table-striped table-bordered table-hover" data-operate-edit="1" data-operate-del="1" width="100%">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'<thead>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'<tr>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<th class="bs-checkbox" data-field="0">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="th-inner">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{if $multiple eq 1}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input id="chkSelectAll" name="chkSelectAll" type="checkbox" />'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</div><div class="fht-cell"></div>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'</th>'."\n";                         
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{if condition="($v.isshowwindow==1) and ($v.columnenname!=\'itemid\')"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<th data-field="{$v.columnenname}">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<div class="th-inner">{$v.columnname}</div><div class="fht-cell"></div>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</th>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{/volist}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'</tr>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'</thead>'."\n";                        
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'<tbody data-listidx="0" id="datalist">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{volist name="lists" id="vo" key="k"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<tr data-index="{$k}">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<td class="bs-checkbox" columnname="itemid">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{if $multiple eq 1}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input data-index="{$k}" name="btSelectItem" type="checkbox" value="{$vo.itemid}" />'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{else}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<input data-index="{$k}" name="btSelectItem" type="radio" value="{$vo.itemid}" />'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</td>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{if condition="($v.isshowwindow==1) and ($v.columnenname!=\'itemid\')"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'<td columnname="{$v.columnenname|ucfirst}">{$vo[$v.columnenname]}</td>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'{/volist}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'</tr>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{/volist}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'</tbody>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'</table>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'<div class="fixed-table-footer" style="display: none;">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<table><tbody><tr></tr></tbody></table>'."\n";
            $stringselect .= "\t\t\t\t".'</div>'."\n";
            $stringselect .= "\t\t\t\t".'<div class="fixed-table-pagination" style="display: block;">'."\n";
            $stringselect .= "\t\t\t\t\t\t".'<div class="pull-left pagination-detail">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<span class="pagination-info">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'显示第 {$offset+1} 到第 {if $totalpage eq $page}{$total}{else}{$limit*$page}{/if} 条记录，总共 {$total} 条记录'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'</span>'."\n";
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n";                            
            $stringselect .= "\t\t\t\t\t\t".'<div class="pull-right pagination">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t".'<ul class="pagination">'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{if $page eq 1 || $offset eq 0 }'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<li class="page-pre"><a href="#" class="btn-disabled disabled">上一页</a></li>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{else}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<li class="page-pre"><a href="{$surl}&offset={$offset-$limit}">上一页</a></li>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{for start="1" end="($totalpage+1)"}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<li class="page-number {if $i eq $page}active{/if}"><a href="{$surl}&offset={$limit*($i-1)}">{$i}</a></li>'."\n";                                 
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{/for}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{if $page < $totalpage}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<li class="page-next"><a href="{$surl}&offset={$offset+$limit}">下一页</a></li>'."\n";                             
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{else}'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<li class="page-next"><a href="#">下一页</a></li>'."\n";
            $stringselect .= "\t\t\t\t\t\t\t\t\t\t".'{/if}'."\n";                            
            $stringselect .= "\t\t\t\t\t\t\t\t".'</ul>'."\n";                             
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n";  
            $stringselect .= "\t\t\t\t\t\t".'</div>'."\n"; 
            $stringselect .= "\t\t\t\t".'</div>'."\n";                                 
            $stringselect .= "\t\t\t\t".'</div>'."\n";                             
            $stringselect .= "\t\t\t\t".'<div class="clearfix"></div>'."\n";
            $stringselect .= "\t\t".'</div>'."\n";
            $stringselect .= "\t\t".'</div>'."\n";
            $stringselect .= "\t\t".'</div>'."\n";
            $stringselect .= "\t\t".'</div>'."\n";                         
            $stringselect .= "\t\t".'</div>'."\n"; 
            $stringselect .= '<script type="text/javascript">'."\n";
            $stringselect .= 'var pagedata = {'."\n";         
            $stringselect .= "\t\t".'list: {$listsjson|raw},columns:{$columnlistjson|raw}'."\n";
            $stringselect .= '};'."\n";                 
            $stringselect .= '</script>'."\n";
            $result = file_put_contents($filename, $string);
            $resultselect = file_put_contents($filenameselect,$stringselect);

            if(@$fp = fopen($filename, 'wb')) {
                flock($fp, LOCK_EX);
                $len = fwrite($fp, $string);
                flock($fp, LOCK_UN);
                fclose($fp);
                if(@$fpselect = fopen($filenameselect,'wb')){
                    flock($fpselect, LOCK_EX);
                    $len = fwrite($fpselect, $stringselect);
                    flock($fpselect, LOCK_UN);
                    fclose($fpselect);
                }
                return 1;
            } else {
                return 0;
            }
        }
    }

    public function makejstemplate($name = ''){
      if($name){
        $ll = Cols::columnread($name);
        $m = $this->get(['enname'=>$name]);
		$dir = '';
		if($m['dir']){
			$dir = APP_PATH.DS.'assets'.DS.'js'.DS.'backend'.DS.$m['dir'].DS; 
			if(!is_dir($dir)){
				mkdir($dir);
			}
		}
		$dir = APP_PATH.DS.'assets'.DS.'js'.DS.'backend'.DS.($m['dir']?$m['dir'].DS:'');
		if(!is_dir($dir)){
			mkdir($dir);
		}        
        $lls = array();
        $string = 'define([\'jquery\',\'bootstrap\', \'backend\', \'table\', \'form\',\'upyun\',\'select2\',\'summernote\'], function ($, undefined, Backend, Table, Form,UpYun,Select2,Summernote) {'."\n";
        $string .= "\t\t".'var Controller = {'."\n";
        $string .= "\t\t\t\t".'index: function () {'."\n";
        $string .= "\t\t\t\t\t\t".'var table = $("#table");'."\n";

        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'.thisaddtabs\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Backend.api.addtabs(Backend.api.replaceids(this, $(this).attr(\'url\')), $(this).attr("title"));'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\',\'.btn-import\',function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'require([\'upload\'], function (Upload) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'Upload.api.plupload($(".btn-import", "#toolbar"), function (data, ret) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/cms.php/'.($m['dir']?$m['dir'].'.'.$name:$name).'/import.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'data: {file: data.url},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (datak) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'#chkSelectAll\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var c = $(this).attr("checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(typeof(c)==\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).attr("checked","");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).removeAttr("checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#table input[name=btSelectItem]").each(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).prop("checked",!$(this).prop("checked"));'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($("#table input[name=btSelectItem]:checked").length>0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-del").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-del").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        
        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'input[name=btSelectItem]\',function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var ll = $("input[name=btSelectItem]:checked").length;'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(ll > 0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(ll == 1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(".btn-edit").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(".btn-edit").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-del").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(typeof($(".btn-more"))!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(".btn-more").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-edit").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-del").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(typeof($(".btn-more"))!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(".btn-more").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";


        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\',\'.cheng_showlist input[type=checkbox]\',function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'url: "/cms.php/'.($m['dir']?$m['dir'].'.'.$name:$name).'/showlist.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'data: {ids:$(this).val(),ischeck:$(this).prop(\'checked\')},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(".btn-edit").on("click",function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'e.preventDefault();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var chenked = $("input[name=\'btSelectItem\']:checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Backend.api.addtabs(Backend.api.replaceids(this, \''.($m['dir']?$m['dir'].'.'.$name:$name).'/edit?ids=\'+chenked[0].value),\'编辑\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(document).on("click",".btn-del",function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'e.preventDefault();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var chenked = $("input[name=\'btSelectItem\']:checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var ids = "";'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'for(var i=0;i<chenked.length;i++){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'ids += chenked[i].value+",";'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(chenked.length==0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var index2 = Layer.confirm(\'请选择记录\',\'请选择\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var id = $(this).data("id");'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var that = this;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var index = Layer.confirm('."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'__(\'Are you sure you want to delete this item?\'),'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'{icon: 3, title: __(\'Warning\'), shadeClose: true},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/cms.php/'.($m['dir']?$m['dir'].'.'.$name:$name).'/dels.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'data: {ids:ids},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if (status == "success") {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'Layer.close(index);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(document).on("click",".btn-delone",function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var ids = $(this).prop("title");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var index = Layer.confirm('."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'__(\'Are you sure you want to delete this item?\'),'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'{icon: 3, title: __(\'Warning\'), shadeClose: true},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/cms.php/'.($m['dir']?$m['dir'].'.'.$name:$name).'/del.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'data: {ids:ids},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if (status == "success") {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'Layer.close(index);location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".');'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$(\'div.keep-open ul li[role="menuitem"] input[type="checkbox"]\').on(\'change\', function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var cn = $(this).attr("data-field");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var cnc = Fast.api.ucfirst(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($(this).is(\':checked\')){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'addColumnMobile(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'addColumnPc(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#datalist .card-view[columnname="+cn+"]").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#table thead tr th[data-field=\'"+cn+"\']").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'//隐藏那个列'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr td[columnname="+cnc+"]").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#table thead tr th[data-field=\'"+cn+"\']").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'//表格切换'."\n";
        $string .= "\t\t\t\t\t\t".'$("#toggleview").on(\'click\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'//转换table视图'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#table thead").show();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var ss = \'\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<tr data-index="\'+i+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td class="bs-checkbox" columnname="\'+v.columnenname+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("div.card-view [columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("div.card-view[columnname=\'"+v.columnenname+"\'] span.value").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td columnname="\'+k+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += s4;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td columnname="caozuo">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += obj.find("div.card-view[columnname=\'caozuo\'] span.value").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</tr>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'//转换cardview视图'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#table thead").hide();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var ss = \'\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<tr data-index="0">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-views">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-view" columnname="\'+v.columnenname+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("td[columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("td[columnname=\'"+k+"\']").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<span class="title">\'+v.columnname+\'</span><span class="value">\'+s4+\'</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-view" columnname="caozuo">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<span class="title" style="text-align: center; vertical-align: middle; ">操作</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<span class="value">\'+obj.find("td[columnname=\'caozuo\']").html()+\'</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</tr>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        foreach ($ll as $k => $v) {
            if($v['optionform']=='select3'&&$v['isshowsearch']==1){
                $string .= "\t\t\t\t\t\t\t\t".'var form = $("form.form-commonsearch");'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'if ($(".selects3", form).size() > 0) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".selects3").bind(\'click\',function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var s1 = \'\';var p = \'\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'url: \'/cms.php/ajax/readcategory?catid=\'+$(this).attr("data-pid"),'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'type: \'post\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'json\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'async: false,'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (ret) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.pss,function(k,v){});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.ps,function(k,v){});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.cs,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s1 = s1 + \'<li><button class="btn btn-primary currents" id="\'+v.id+\'" type="button">\'+v.name+\'</button>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.child>0){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s1 = s1 + \'&nbsp;<button class="btn btn-primary childs" id="\'+v.id+\'" type="button">&gt;</button></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var s = \'<div class="container">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'s = s + \'<div class="row">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<div class="col-xs-12">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<ul id="breadcrumb" class="breadcrumb">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<li><a href="javascript:;" title="\' + $(this).attr("data-pid") + \'">回到顶级</a> <span class="divider">></span></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'</ul>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'</div>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'s = s + \'</div>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'s = s + \'<div class="row">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<ul id="dcategory" class="dcategory">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + s1;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'</ul>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'s = s + \'</div>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'s = s + \'</div>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$(document).delegate(".breadcrumb a","click",function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var s = \'\';var p = \'\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'url: \'/cms.php/ajax/readcategory?catid=\'+$(this).prop("title"),'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'type: \'post\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'json\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (ret) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.pss,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<li><a href="javascript:;" title="\' + v.id + \'">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + v.name + \'</a>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<span class="divider">></span></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.ps,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<li><a href="javascript:;" title="\' + v.id + \'">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + v.name + \'</a>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<span class="divider">></span></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.cs,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<li><button class="btn btn-primary currents" id="\'+v.id+\'" type="button">\'+v.name+\'</button>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.child>0){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'&nbsp;<button class="btn btn-primary childs" id="\'+v.id+\'" type="button">&gt;</button></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#breadcrumb").html(\'<li><a href="javascript:;" title="0">回到顶级</a> <span class="divider">></span></li>\'+p);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#dcategory").html(s);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$(document).delegate("button.childs","click",function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s = \'\';var p = \'\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: \'/cms.php/ajax/readcategory?catid=\'+$(this).prop("id"),'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: \'post\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'json\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (ret) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.pss,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<li><a href="javascript:;" title="\' + v.id + \'">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + v.name + \'</a>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<span class="divider">></span></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.ps,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<li><a href="javascript:;" title="\' + v.id + \'">\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + v.name + \'</a>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'p = p + \'<span class="divider">></span></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(ret.cs,function(k,v){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'<li><button class="btn btn-primary currents" id="\'+v.id+\'"   type="button">\'+v.name+\'</button>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.child>0){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'s = s + \'&nbsp;<button class="btn btn-primary childs" id="\'+v.id+\'" type="button">&gt;</button></li>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#breadcrumb").html(\'<li><a href="javascript:;" title="0">回到顶级</a> <span class="divider">></span></li>\'+p);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#dcategory").html(s);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(document).delegate("button.currents","click",function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$(".selected3").html($(this).html());'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#catid").val($(this).prop("id"));'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'layer.closeAll();'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var ll = layer.open({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: 1'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',title: \'选择类别\''."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',content: s'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',anim: \'down\''."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',closeBtn: true'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',area:[\'90%\',\'90%\']'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".',style: \'position:fixed; left:0; top:0; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;\''."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t".'}'."\n";
            }
            if($v['optiondepend']){
                /*
                    $(document).on("change","select[name=\''.$v[''].'[]\']",function(e){
                    var s = $(this).data("relate");
                    $.ajax({
                        type: "post",
                        url: "ajax/city.html",
                        data: {pid:$(this).val()},
                        dataType: 'JSON',
                        success: function (ret) {
                            var str = '';
                            str += '<option value="0">请选择</option>';
                            $.each(eval(ret), function (k1, v1) {
                                $.each(eval(v1), function (k, v) {
                                    str += '<option value="' + v.itemid + '"';
                                    if(v.selected==1){
                                        str += ' selected="selected">';
                                    }else{
                                        str += '>';
                                    }
                                    str += v.name;
                                    str += '</option>';
                                });
                            });
                            $("#"+s).html(str);
                            $("#"+s).selectpicker('refresh');
                        },
                        error: function () {alert('编辑失败');},
                        complete: function () {}
                    });
                });
                */
            }
        }
        $string .= "\t\t\t\t\t\t".'if($(window).width()<768){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'$(window).resize(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($(window).width()<=768){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(!$("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($(window).width()>768){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t".'},'."\n";

        $string .= "\t\t\t\t".'select:function(){'."\n";
        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'input[name=btSelectItem]\',function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($("input[name=btSelectItem]:checked").length>0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-choose-multi").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-choose-multi").addClass(\'disabled\');'."\n";   
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'#chkSelectAll\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var c = $(this).attr("checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(typeof(c)==\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).attr("checked","");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).removeAttr("checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#table input[name=btSelectItem]").each(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(this).prop("checked",!$(this).prop("checked"));'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($("#table input[name=btSelectItem]:checked").length>0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-choose-multi").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-choose-multi").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'// 选中多个'."\n";
        $string .= "\t\t\t\t\t\t".'$(document).on("click", ".btn-choose-multi", function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var jstr = \'[\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var tditemid = $(this).find("td[columnname=itemid]");'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var tditemidcheck = tditemid.find("input[name=btSelectItem]:checked");'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(typeof(tditemidcheck.val())!="undefined"){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'jstr = jstr + \'{\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'jstr = jstr + \'"itemid":"\' + tditemidcheck.val() + \'",\';';

        foreach ($ll as $k => $v) {
            if($v['isshowwindow']&&$v['columnenname']!='itemid'){
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var td'.$v['columnenname'].' = $(this).find("td[columnname='.ucfirst($v['columnenname']).']");'."\n"; 
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'jstr = jstr + \'"'.$v['columnenname'].'":"\' + td'.$v['columnenname'].'.html()+ \'",\';'."\n";                
            }
        }
        //$string = substr($string,0,strlen($string)-1);
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'jstr = jstr.substring(0,jstr.length-1);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'jstr = jstr + \'},\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var newStr = jstr.substring(0,jstr.length-1);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'newStr = newStr + \']\';'."\n";              
        $string .= "\t\t\t\t\t\t\t\t".'var multiple = Backend.api.query(\'multiple\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'multiple = multiple == \'1\' ? 1 : 0;'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Fast.api.close(newStr);'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'$("#toggleview").on(\'click\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'//转换table视图'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#table thead").show();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var ss = \'\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<tr data-index="\'+i+\'">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td class="bs-checkbox" columnname="\'+v.columnenname+\'">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("div.card-view [columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("div.card-view[columnname=\'"+v.columnenname+"\'] span.value").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td columnname="\'+k+\'">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += s4;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</tr>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'//转换cardview视图'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#table thead").hide();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var ss = \'\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<tr data-index="0">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-views">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-view" columnname="\'+v.columnenname+\'">\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("td[columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("td[columnname=\'"+k+"\']").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<span class="title">\'+v.columnname+\'</span><span class="value">\'+s4+\'</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</tr>\''."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t\t\t".'Form.api.bindevent($("form[role=commonsearch]"));'."\n";
        $string .= "\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t\t".'},'."\n";
        
        $string .= "\t\t\t\t".'add: function () {'."\n";
        foreach ($ll as $k => $v) {
            if($v['optionform']=='upyunimage'||$v['optionform']=='upyunfile'){
                $string .= "\t\t\t\t\t\t\t\t".'$("#upyun_upload'.$v['columnenname'].'").bind(\'change\',function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'UpYun.uploadByAjax(\'upyun_upload'.$v['columnenname'].'\',\'c-'.$v['columnenname'].'\',\'andiffnet/test\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
            }

            if($v['optionform'] == 'openwindow'){
                //初始化关联模型
                $modelrelate = $this->get(['enname'=>$v['rname']]);
                $string .= "\t\t\t\t\t\t".'$(".btn-openwindow").bind(\'click\',function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var that = this;'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var multiple = $(this).data("multiple") ? $(this).data("multiple") : false;'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var mimetype = $(this).data("mimetype") ? $(this).data("mimetype") : \'\';'."\n";  
                //$string .= "\t\t\t\t\t\t\t\t".''; 
                if($v['optionurl']){
                    $string .= "\t\t\t\t\t\t\t\t".'parent.Fast.api.open("'.$v['optionurl'].'?element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __(\'Choose\'), {'."\n";
                }else{
                    $string .= "\t\t\t\t\t\t\t\t".'parent.Fast.api.open("'.($modelrelate['dir']?$modelrelate['dir'].'.':'').$modelrelate['enname'].'/select?element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __(\'Choose\'), {'."\n";
                }    
                $string .= "\t\t\t\t\t\t\t\t".'callback: function (data) {'."\n"; 
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var button = $("#" + $(that).attr("id"));//当前按钮的id'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var maxcount = $(button).data("maxcount");//最大数量'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var input_id = $(button).data("input-id") ? $(button).data("input-id") : "";'."//指定元素的id\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'maxcount = typeof maxcount !== "undefined" ? maxcount : 0;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var obj = jQuery.parseJSON(data);'."\n";
                $listc = model('Column')->getColumnsByShowwindow($v['rname']);
                foreach ($listc as $k2 => $v2) {
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'var '.$v2['columnenname'].'s = \'\''."\n";
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$.each(obj, function (k, v) {'."\n";
                foreach ($listc as $k2 => $v2) {
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".$v2['columnenname'].'s = '.$v2['columnenname'].'s + v.'.$v2['columnenname'].' + \',\';'."\n";
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                foreach ($listc as $k2 => $v2) {
                    if($v2['columnenname']=='itemid'){
                        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#" + input_id).val('.$v2['columnenname'].'s.substring(0,'.$v2['columnenname'].'s.length-1));'."\n";
                    }else{
                        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#" + input_id).parent().next().html(\'<label>\'+names.substring(0,names.length-1)+\'</label>\');'."\n";
                        //$string .= "\t\t\t\t\t\t\t\t\t\t".'$("#'.$v['rname'].$v2['columnenname'].'").html('.$v2['columnenname'].'s.substring(0,'.$v2['columnenname'].'s.length-1));'."\n";
                    }
                }    
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";   
                $string .= "\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t".'return false;'."\n";
                $string .= "\t\t\t\t\t\t\t".'});'."\n";
            }
            if($v['optiondepend']){
                $string .= "\t\t\t\t\t\t".'$(document).on("change","#c-'.$v['optiondepend'].'",function(e){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'url: "'.$v['optionurl'].'",'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'data: {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".$v['optiondepend'].':$(this).val()'."\n";
                
                $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'success: function (ret) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var str = \'\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'<option value="">请选择</option>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(ret), function (k, v) {'."\n";
                //$string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(v1), function (k, v) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'<option value="\' + v.itemid + \'"\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.selected==1){str += \' selected="selected">\';}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'else{str += \'>\';}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += v.name;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'</option>\';'."\n";
                //$string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#c-'.$v['columnenname'].'").html(str);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#c-'.$v['columnenname'].'").selectpicker(\'refresh\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'error: function () {alert(\'编辑失败\');},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t".'});'."\n";
            }
        }
        $string .= "\t\t\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t".'edit: function () {'."\n";
        foreach ($ll as $k => $v) {
            if($v['optionform']=='upyunimage'||$v['optionform']=='upyunfile'){
                $string .= "\t\t\t\t\t\t\t\t".'$("#upyun_upload'.$v['columnenname'].'").bind(\'change\',function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'UpYun.uploadByAjax(\'upyun_upload'.$v['columnenname'].'\',\'c-'.$v['columnenname'].'\',\'andiffnet/test\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
            }
            if($v['optionform'] == 'openwindow'){
                //初始化关联模型
                $modelrelate = $this->get(['enname'=>$v['rname']]);
                $string .= "\t\t\t\t\t\t".'$(".btn-openwindow").bind(\'click\',function(){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var that = this;'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var multiple = $(this).data("multiple") ? $(this).data("multiple") : false;'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'var mimetype = $(this).data("mimetype") ? $(this).data("mimetype") : \'\';'."\n";  
                //$string .= "\t\t\t\t\t\t\t\t".''; 
                if($v['optionurl']){
                    $string .= "\t\t\t\t\t\t\t\t".'parent.Fast.api.open("'.$v['optionurl'].'?element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __(\'Choose\'), {'."\n";
                }else{
                    $string .= "\t\t\t\t\t\t\t\t".'parent.Fast.api.open("'.($modelrelate['dir']?$modelrelate['dir'].'.':'').$modelrelate['enname'].'/select?element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __(\'Choose\'), {'."\n";
                }    
                $string .= "\t\t\t\t\t\t\t\t".'callback: function (data) {'."\n"; 
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var button = $("#" + $(that).attr("id"));//当前按钮的id'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var maxcount = $(button).data("maxcount");//最大数量'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var input_id = $(button).data("input-id") ? $(button).data("input-id") : "";'."//指定元素的id\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'maxcount = typeof maxcount !== "undefined" ? maxcount : 0;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'var obj = jQuery.parseJSON(data);'."\n";
                $listc = model('Column')->getColumnsByShowwindow($v['rname']);
                foreach ($listc as $k2 => $v2) {
                    $string .= "\t\t\t\t\t\t\t\t\t\t".'var '.$v2['columnenname'].'s = \'\''."\n";
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$.each(obj, function (k, v) {'."\n";
                foreach ($listc as $k2 => $v2) {
                    $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".$v2['columnenname'].'s = '.$v2['columnenname'].'s + v.'.$v2['columnenname'].' + \',\';'."\n";
                }
                $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                foreach ($listc as $k2 => $v2) {
                    if($v2['columnenname']=='itemid'){
                        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#" + input_id).val('.$v2['columnenname'].'s.substring(0,'.$v2['columnenname'].'s.length-1));'."\n";
                    }else{
                        $string .= "\t\t\t\t\t\t\t\t\t\t".'$("#" + input_id).parent().next().html(\'<label>\'+names.substring(0,names.length-1)+\'</label>\');'."\n";
                        //$string .= "\t\t\t\t\t\t\t\t\t\t".'$("#'.$v['rname'].$v2['columnenname'].'").html('.$v2['columnenname'].'s.substring(0,'.$v2['columnenname'].'s.length-1));'."\n";
                    }
                }    
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";   
                $string .= "\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t".'return false;'."\n";
                $string .= "\t\t\t\t\t\t\t".'});'."\n";
            }

            if($v['optiondepend']){
                
                $string .= "\t\t\t\t\t\t".'$(document).on("change","#c-'.$v['optiondepend'].'",function(e){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'url: "'.$v['optionurl'].'",'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'data: {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".$v['optiondepend'].':$(this).val()'."\n";
                
                $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'success: function (ret) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'var str = \'\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'<option value="">请选择</option>\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(ret), function (k, v) {'."\n";
                //$string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'$.each(eval(v1), function (k, v) {'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'<option value="\' + v.itemid + \'"\';'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.selected==1){str += \' selected="selected">\';}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'else{str += \'>\';}'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += v.name;'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'str += \'</option>\';'."\n";
                //$string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#c-'.$v['columnenname'].'").html(str);'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$("#c-'.$v['columnenname'].'").selectpicker(\'refresh\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'error: function () {alert(\'编辑失败\');},'."\n";
                $string .= "\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
                $string .= "\t\t\t\t\t\t".'});'."\n";
            }
        }
        $string .= "\t\t\t\t\t\t\t\t".'$(".returnback").click(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'history.back();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t".'api: {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'bindevent: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'Form.api.bindevent($("form[role=form]"));'."\n";
        //$string .= "\t\t\t\t\t\t\t\t\t\t".'Form.api.bindevent($("form.form-commonsearch"));'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'};'."\n";
        $string .= "\t\t\t\t".'return Controller;'."\n";
        $string .= "\t\t".'});'."\n";

        $string .= 'function creatList(obj, list){'."\n";
        $string .= "\t\t".'$.each(eval(obj), function(i,item) {'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'temp.text = item.name;'."\n";
        $string .= "\t\t\t\t".'temp.value = item.id;'."\n";
        $string .= "\t\t\t\t".'list.push(temp);'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= '}'."\n";

        $string .= '//补足表格的列(PC)'."\n";
        $string .= 'function addColumnPc(key){'."\n";
        $string .= "\t\t".'var l = 10000;//初始化顺序'."\n";
        $string .= "\t\t".'var columnenname = \'\';var columnname = \'\';'."\n";
        $string .= "\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'if(k.toLowerCase()==key){'."\n";
        $string .= "\t\t\t\t\t\t".'columnenname = v.columnenname;'."\n";
        $string .= "\t\t\t\t\t\t".'columnname = v.columnname;'."\n";
        $string .= "\t\t\t\t\t\t".'l = v.listorder;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'if((v.listorder>l)&&(v.isshowlist==1)){'."\n";
        $string .= "\t\t\t\t\t\t".'var html = "";'."\n";
        $string .= "\t\t\t\t\t\t".'$("#table thead").find("tr th[data-field=\'"+v.columnenname+"\']").before(\'<th data-field="\'+columnenname+\'"><div class="th-inner">\'+columnname+\'</div><div class="fht-cell"></div></th>\');'."\n";
        $string .= "\t\t\t\t\t\t".'var list = eval(pagedata.list);'."\n";
        $string .= "\t\t\t\t\t\t".'var cv = \'\';'."\n";
        $string .= "\t\t\t\t\t\t".'var lst = $("#table tbody tr").find("td[columnname="+Fast.api.ucfirst(v.columnenname)+"]");'."\n";;
        $string .= "\t\t\t\t\t\t".'//把单元格的列加上'."\n";
        $string .= "\t\t\t\t\t\t".'lst.each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(this).before(\'<td columnname="\'+Fast.api.ucfirst(columnenname)+\'">\'+list[i][columnenname.toLowerCase()]+\'</td>\');'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= '}'."\n";

        $string .= '//补足表格的列(Mobile)'."\n";
        $string .= 'function addColumnMobile(key){'."\n";
        $string .= "\t\t".'var l = 10000;//初始化顺序'."\n";
        $string .= "\t\t".'var columnenname = \'\';var columnname = \'\';'."\n";
        $string .= "\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'if(k.toLowerCase()==key){'."\n";
        $string .= "\t\t\t\t\t\t".'columnenname = v.columnenname;'."\n";
        $string .= "\t\t\t\t\t\t".'columnname = v.columnname;'."\n";
        $string .= "\t\t\t\t\t\t".'l = v.listorder;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'if((v.listorder>l)&&(v.isshowlist==1)){'."\n";
        $string .= "\t\t\t\t\t\t".'var html = "";'."\n";
        $string .= "\t\t\t\t\t\t".'var list = eval(pagedata.list);'."\n";
        $string .= "\t\t\t\t\t\t".'var cv = \'\';'."\n";
        $string .= "\t\t\t\t\t\t".'var lst = $("#datalist tr td").find("div[columnname="+v.columnenname+"]");'."\n";
        $string .= "\t\t\t\t\t\t".'//把单元格的列加上'."\n";
        $string .= "\t\t\t\t\t\t".'lst.each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(this).before(\'<div class="card-view" columnname="\'+columnenname.toLowerCase()+\'"><span class="title">\'+columnname+\'</span><span class="value">\'+list[i][columnenname.toLowerCase()]+\'</span></div>\');'."\n";
        $string .= "\t\t\t\t\t\t".'});return false;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= "\t\t".'return false;'."\n";
        $string .= '}'."\n";
        $string .= '';
        //     });
        // }
        $filename = APP_PATH.DS.'assets'.DS.'js'.DS.'backend'.DS.($m['dir']?$m['dir'].DS:'').$name.'.js';
        $result = file_put_contents($filename, $string);
        if(@$fp = fopen($filename, 'wb')) {
            flock($fp, LOCK_EX);
            $len = fwrite($fp, $string);
            flock($fp, LOCK_UN);
            fclose($fp);
            return 1;
        } else {
            return 0;
        }
      }
    }
    

    //得到某个实体的子实体（完全隶属关系）
    public function getModelByPid($pid = ''){
        return $this->where('pid',$pid)->select();
    }

}
?>
